I am trying to convert my native iOS app into a hybrid app using HTML 5.
After doing a research I ended up with jQuery mobile + phoneGap.
My questions are
- Is it possible to mix html 5 and native iOS features within a single
view? For example can I use html text field to get the value and use
it to do some conversion using iOS picker.
- Is it possible to navigate to a native xib from an html page?
- And finally is there any better solution to create a hybrid app?
thanks in advance
May be i am late here but first two question's answer is YES you can. You can call Objective C method which has a Picker displaying codes and Navigating/pushing other Views, from your web having Javascript. You just need to track them in your native app using UIWebViewDelegate. Here's example how i did this :
// In Your Javascript file, inside the method from where you want to invoke Pickerview or want to push another native view
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", "js-frame:myObjectiveCFunction";
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
In your Native Objective - C file : include <<UIWebViewDelegate>>
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
if ([[[request URL] absoluteString] hasPrefix:@"js-frame:"]) {
// Extract the selector name from the URL
NSArray *components = [requestString componentsSeparatedByString:@":"];
NSString *functionName = [components objectAtIndex:1];
// Call the given selector
[self performSelector:NSSelectorFromString(functionName)];
// Cancel the location change
return NO;
}
// Accept this location change
return YES;
}
- (void)myObjectiveCFunction {
// Do whatever you want!
// show Native picker view
// Push another native View
}
In the same way , you can even send the parameters from HTML page to Objective c.
// -----------------------------------