0

iPhone过去 2 年我一直在开发本机应用程序。但现在我正在努力学习phone gap。我已经看到了index.html用作起始页的电话间隙示例,但是我想制作一个同时具有 . 和 . 的应用程序nativephone gap所以任何人都可以指导我如何使用本机组件,如viewControllernavigationBartabBarController组件和电话间隙。另外,如果您有任何对我有帮助的教程,我会看到很多教程,但都是旧的,不能在我的 Xcode 4.5 上运行。

4

2 回答 2

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
于 2012-12-19T06:57:24.647 回答
0

对于本机功能,您可以使用插件,甚至可以自己创建

phonegap 插件

如何创建插件

你也可以参考这个博客

于 2012-12-19T06:48:13.043 回答