我在过去2年里一直在开发iPhone
本机应用程序。但现在我正在努力学习phone gap
。我已经看到了使用index.html
作为起始页的手机间隙样本,但我想同时制作一个同时包含native
和phone gap
的应用。所以任何人都可以指导我如何使用viewController
,navigationBar
,tabBarController
组件和电话差距等原生组件。另外,如果您有任何对我有帮助的教程,我会看到许多教程,但所有教程都是旧的,不能在我的Xcode 4.5上运行。
答案 0 :(得分:2)
在插件的帮助下,您可以在手机间隙中使用本机代码 例如,我粘贴了一些代码
#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
答案 1 :(得分:0)