簡體   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