2014-01-13 51 views
1

我有PhoneGap 2.8.1 iPhone應用程序,我最近面臨奇怪的問題: 我寫了插件,存儲一些應用程序的祕密在設備上,哈希給出數據(使用這些祕密)並將這個哈希值返回給JS。我的用於phonegap應用程序的iOS插件曾經工作過一次。當應用程序再次啓動它不工作,直到我去背景並返回到應用程序

當我安裝後第一次運行我的應用程序時,一切正常。 但是當我再次啓動它時,應用程序在我的插件方法開始之前(或者可能開始)凍結。 開始之前加載的第三方插件可以,但是當涉及到我的插件時 - 什麼都沒有發生。

在Xcode控制檯上沒有任何東西在weinre控制檯上。空值。沒有錯誤異常,沒有來自本地代碼的日誌。 當我嘗試從weinre控制檯手動運行一些本地方法時,也沒有任何反應。

但是當我點擊主頁按鈕並返回到應用程序背景時,一切都神奇地開始工作!

有沒有人有類似的問題?任何解決方案線索?

+0

你確定你正在使用的插件「deviceready」被觸發後? –

+0

是的,我的整個應用程序啓動後,deviceready事件被觸發。 –

+0

你能不能請示一些代碼?喜歡你如何使用你的插件? –

回答

0

我有散列數據的方法將被髮送到我的API的請求。我用這樣的:

window.plugins.protocol.hamac data, (results) => 
    # work with results 

本機代碼看起來是這樣的:

- (void)hamac:(CDVInvokedUrlCommand*)command { 
    NSLog(@"HAMAC STARTED!"); 
    CDVPluginResult* pluginResult = nil; 

    @try { 
     NSDictionary* data = [command.arguments objectAtIndex:0]; 

     if (data != nil) { 
      // prepare string to be hashed 

      pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary: @{ 
                             @"status": @YES, 
                             @"h": [self sha1:[NSString stringWithFormat:@"%@", stringToHash] 
                             }]; 
     } else { 
      pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary: @{ 
                              @"status": @NO, 
                              @"error": @"No data!" 
                              }]; 
     } 
    } @catch (NSException* e) { 
     pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary: @{ 
                             @"status": @NO, 
                             @"error": @"Failed to hash data" 
                             }]; 
    } 

    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 
} 
相關問題