这是什么意思:+ [UAirship executeUnsafeTakeOff:]?

时间:2014-01-14 05:46:04

标签: ios apple-push-notifications urbanairship.com

我正在尝试使用Urban Airship设置推送通知,我相信我的配置文件或ssl证书有问题。该应用不会提示用户提供推送通知权限,但我没有获得“无效”#a; aps-environment"为应用程序找到的权利字符串'消息,我可以在aps-environment中看到.mobileprovision权利。

我无法在+[UAirship executeUnsafeTakeOff:]找到任何文档,所以我想知道是否有人知道这可能意味着什么?

此外,设备令牌将以nil的形式返回,如Urban Airship记录的那样:

  

[D] - [UAPush updateRegistrationForcefully:] [Line 544]设备令牌是   零。将在稍后时间进行注册

[UAirship takeOff:config]调用之前没有运行Urban Airship代码,并且应用程序不会因错误而崩溃。

1 个答案:

答案 0 :(得分:1)

我不太了解Urban Airship,我可以猜测。

takeOff确保executeUnsafeTakeoff中提供的实际实施仅发生一次。它确保当前线程是主线程,然后确保它只发生一次。

因此,收到executeUnsafeTakeoff错误实际上只会告诉您出现问题,例如config failed to验证`(见下文)。

您需要确保该应用可以接收推送通知,如您所述。

以下是takeOff

+ (void)takeOff {
    [UAirship takeOff:[UAConfig defaultConfig]];
}

+ (void)takeOff:(UAConfig *)config {

    // takeOff needs to be run on the main thread
    if (![[NSThread currentThread] isMainThread]) {
        NSException *mainThreadException = [NSException exceptionWithName:UAirshipTakeOffBackgroundThreadException
                                                                   reason:@"UAirship takeOff must be called on the main thread."
                                                                 userInfo:nil];
        [mainThreadException raise];
    }

    dispatch_once(&takeOffPred_, ^{
        [UAirship executeUnsafeTakeOff:config];
    });
}

以下是executeUnsafeTakeoff

/*
 * This is an unsafe version of takeOff - use takeOff: instead for dispatch_once
 */
+ (void)executeUnsafeTakeOff:(UAConfig *)config {
    // Airships only take off once!
    if (_sharedAirship) {
        return;
    }

    [UAirship setLogLevel:config.logLevel];

    _sharedAirship = [[UAirship alloc] init];
    _sharedAirship.config = config;

    // Ensure that app credentials have been passed in
    if (![config validate]) {

        UA_LERR(@"The AirshipConfig.plist file is missing and no application credentials were specified at runtime.");

        // Bail now. Don't continue the takeOff sequence.
        return;
    }

    UA_LINFO(@"App Key: %@", _sharedAirship.config.appKey);
    UA_LINFO(@"App Secret: %@", _sharedAirship.config.appSecret);
    UA_LINFO(@"Server: %@", _sharedAirship.config.deviceAPIURL);

    if (config.automaticSetupEnabled) {

        _sharedAirship.appDelegate = [[UAAppDelegateProxy alloc ]init];

        //swap pointers with the initial app delegate
        @synchronized ([UIApplication sharedApplication]) {
            _sharedAirship.appDelegate.originalAppDelegate = [UIApplication sharedApplication].delegate;
            _sharedAirship.appDelegate.airshipAppDelegate = [[UAAppDelegate alloc] init];
            [UIApplication sharedApplication].delegate = _sharedAirship.appDelegate;
        }
    }


    // Build a custom user agent with the app key and name
    [_sharedAirship configureUserAgent];

    // Set up analytics
    _sharedAirship.analytics = [[UAAnalytics alloc] initWithConfig:_sharedAirship.config];
    [_sharedAirship.analytics delayNextSend:UAAnalyticsFirstBatchUploadInterval];

    /*
     * Handle Debug Options
     */

    //For testing, set this value in AirshipConfig to clear out
    //the keychain credentials, as they will otherwise be persisted
    //even when the application is uninstalled.
    if (config.clearKeychain) {

        UA_LDEBUG(@"Deleting the keychain credentials");
        [UAKeychainUtils deleteKeychainValue:_sharedAirship.config.appKey];

        UA_LDEBUG(@"Deleting the UA device ID");
        [UAKeychainUtils deleteKeychainValue:kUAKeychainDeviceIDKey];
    }

    if (!config.inProduction) {
        [_sharedAirship validate];
    }

    if (config.cacheDiskSizeInMB > 0) {
        UA_LINFO("Registering UAURLProtocol");
        [NSURLProtocol registerClass:[UAURLProtocol class]];
    }

    // The singleton is now ready for use!
    _sharedAirship.ready = true;


    //create/setup user (begin listening for device token changes)
    [[UAUser defaultUser] initializeUser];

}