繁体   English   中英

如何使用手机差距和原生应用程序制作iPhone应用程序

[英]How to make a iPhone app using both phone gap and native app

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

在插件的帮助下,您可以在手机间隙中使用本机代码,例如我粘贴一些代码

#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

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

phonegap插件

如何创建插件

您也可以参考这个博客

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM