Reputation: 266
I have being developing iPhone
native application for last 2 year. But now I am trying to learn phone gap
. I have seen the sample of phone gap which use index.html
as a start page, But I want to make an app with both native
as well as phone gap
.So can any one guide me how to use the native components like viewController
, navigationBar
, tabBarController
component and phone gap. Also if you have any tutorial which will be helpful for me I have see many tutorial but all are old which doesn't run on my Xcode 4.5.
Upvotes: 0
Views: 898
Reputation: 363
With the help of plugin you can use native code in phone gap for example I am pasting some code
#import <UIKit/UIKit.h>
#import <Cordova/CDVPlugin.h>
@interface PushToken : CDVPlugin
{
NSString* callbackID;
}
@property (nonatomic, copy) NSString* callbackID;
- (void) getToken:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
@end
#import "PushToken.h"
#import "AppDelegate.h"
@implementation PushToken
@synthesize callbackID;
-(void)getToken:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
self.callbackID = [arguments pop];
NSString *token = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).token;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[token stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if(token.length != 0)
{
[self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]];
}else {
[self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]];
}
}
@end
.js file
var PushToken = {
getToken: function(types, success, fail) {
return cordova.exec(success, fail, "PushToken", "getToken", types);
}
};
including .js file
<script src="PushToken.js"></script>
calling
PushToken.getToken(
["getToken"] ,
function(token) {
devToken = token;
//navigator.notification.alert(devToken);
},
function(error) {
navigator.notification.alert("Error :Token Not Found "+error);
}
);
may be helpful
thanks
Upvotes: 2
Reputation: 1424
for Native features you can make use of plugins and can even create by yourself
You can also refer to THIS blog
Upvotes: 0