iOS - Using native pages in hybrid applicationsimprove this page | report issue
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 MobileFirst project.
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.