iOS - Using native pages
This tutorial explains how to integrate native and web "pages" in an iOS application by using the
This tutorial covers the following topics:
- Creating a native page
- Returning control to the web view
- Sample application
- Implement the
WL.NativePage.show()method to open the native page:
nativePageClassName: The name of a native iOS
UIViewControllerinstance to start.
backFromNativePage: A callback function to call when the native page closes.
params: Optional custom parameters object to pass to the native code.
- To handle the callback function, write the following code:
backFromNativePage(data)parameter can pass data back to the web part of an application after the native closes.
Creating a native page
To manage a native page, proceed as follows:
- Open the generated iOS projects in Xcode.
- Add a new Cocoa Touch Class file, make sure that it is a subclass of
UIViewControllerand save the file in the
Classesfolder of the Xcode project.
If you work with existing
.hfiles, reference the files while in Xcode.
.hfiles only in the
iphone\native\Classesfolder in Eclipse is not sufficient, because these files are not referenced in the Xcode project unless they have been added in Xcode.
- To retrieve custom data parameters that are passed from the web view, use the
Returning control to the web view
When the native page switches back to the web view, a call to the
[NativePage showWebView:] method is necessary.
To pass data back to the web view, use the
NSDictionary object. For example:
Click to download the Studio project.