2017-06-14 15 views
0

首先啓動的ViewController,讓我解釋一下它是如何保持使用科爾多瓦項目中的Objective-C

應用結構我這裏有兩個應用程序

首先,基於iOS的應用原生的Objective-C是完美工作,原生應用程序的任務是在應用程序啓動後啓動相機,捕獲圖像並執行一些OpenGL處理​​,顯示捕獲的圖像。

這是通過調用視圖控制器類來完成我的main.m文件中如下圖所示

#import <UIKit/UIKit.h> 
#import "ViewController.h" 

int main(int argc, char * argv[]) { 
    @autoreleasepool { 
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([ViewController class])); 
    } 
} 

這個視圖控制器類有一些特性,這得到了應用程序運行& &啓動一個故事板

現在對於cordova應用程序,我創建了一個插件並將所有本機文件集成到插件中,因此一旦我們添加了插件,它就會添加所有資源,包括源文件,資源文件,資產,故事板等。

當我們觸發在JavaScript中的插件,它會調用本地類CustomPlugin這是插件的起點,下面是相同的

CustomPlugin.h

#import <Cordova/CDV.h> 
#import "ViewController.h" 

@interface CustomPlugin : CDVPlugin 

- (void) pluginInitialize; 

- (void) process:(CDVInvokedUrlCommand*)command; 

@end 

的頭&執行代碼CustomPlugin.h

#import "CustomPlugin.h" 
#import "ViewController.h" 


@interface CustomPlugin() 

@end 

@implementation CustomPlugin 

NSString *_routeChangedCallbackId; 
@synthesize viewc; 


- (void) pluginInitialize { 
    NSLog(@"CustomPlugin:pluginInitialize"); 

    _routeChangedCallbackId = nil; 
} 

- (void) process:(CDVInvokedUrlCommand*)command 
{ 
    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"test"]; 
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 
} 

@end 

此實現目前剛剛發回的響應樣本消息給呼叫者

我想實現的是能夠調用/啓動/初始化的ViewController特徵,因爲在本機

工作請大家給予我的冗長的問題,但它是必要的,因爲我太新到iOS。

回答

0

的pluginInitialize方法應CDVPluginResult和commandDelegate方法之間被稱爲:

- (void) process:(CDVInvokedUrlCommand*)command 
    { 
     CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"test"]; 

     [self pluginInitialize]; 

     [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 
    } 

https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithObjects/WorkingwithObjects.html