【问题标题】:My iOS plugin for phonegap app worked once. When app is started again it doesn't work until I go background and return to app我的 phonegap 应用程序的 iOS 插件工作过一次。当应用程序再次启动时,它不起作用,直到我进入后台并返回应用程序
【发布时间】:2014-01-13 14:22:31
【问题描述】:

我有使用 PhoneGap 2.8.1 制作的 iPhone 应用程序,我最近遇到了奇怪的问题: 我已经编写了在设备上存储一些应用程序机密的插件,散列给定数据(使用这些机密)并将此散列返回给 JS。

当我在安装后第一次运行我的应用程序时,一切正常。 但是当我再次启动它时,应用程序在我的插件方法开始之前(或者可能在)开始冻结。 3rd 方插件在启动之前加载正常,但是当涉及到我的插件时 - 什么都没有发生。

Xcode 控制台上什么都没有,weinre 控制台上什么都没有。空值。没有错误异常,没有来自本机代码的日志。 当我尝试从 weinre 控制台手动运行一些本机方法时,也没有任何反应。

但是当我通过点击主页按钮打开我的应用程序背景并返回它时,一切都神奇地开始工作了!

有没有人有类似的问题?有什么解决办法吗?线索?

【问题讨论】:

  • 您确定在“deviceready”触发后使用插件吗?
  • 是的,我的整个应用在 deviceready 事件触发后启动。
  • 你能显示一些代码吗?比如你是如何使用你的插件的?
  • 您找到解决方案了吗?我遇到了类似的问题,但是使用 Phonegap 的媒体和对话框插件,我在网上找不到任何相关信息。
  • 哦,是的,原来我在 JS 中有错误(使用不存在的方法)。而那个错误阻止了一切。所以检查你的 JS!

标签: ios iphone plugins cordova


【解决方案1】:

我有一种方法可以对数据进行哈希处理,这些数据将在请求中发送到我的 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];
}

【讨论】:

    猜你喜欢
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 2013-12-04
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多