我正在尝试使用 Urban Airship 设置推送通知,但我认为我在配置文件或 SSL 证书方面遇到了问题。该应用程序没有提示用户获得推送通知权限,但我没有收到“找不到应用程序的有效“aps-environment”授权字符串”消息,我可以在中看到 aps-environment
授权.mobileprovision
。
我找不到关于 +[UAirship executeUnsafeTakeOff:]
的任何文档,所以我想知道是否有人知道这意味着什么?
此外,设备 token 返回为 nil,如 Urban Airship 所记录:
[D] -[UAPush updateRegistrationForcefully:] [Line 544] Device token is nil. Registration will be attempted at a later time
在 [UAirship takeOff:config]
调用之前没有运行 Urban Airship 代码,应用程序不会因错误而崩溃。
最佳答案
在不太了解 Urban Airship 的情况下,我可以提供一个猜测。
takeOff
确保 executeUnsafeTakeoff
中提供的实际实现仅发生一次。它确保当前线程是主线程,然后确保它只发生一次。
因此,收到 executeUnsafeTakeoff
错误实际上只会告诉您出现了问题,例如配置无法
验证`(见下文)。
正如您提到的,您需要确保应用程序可以接收推送通知。
这是起飞
:
+ (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];
}
关于ios - 这是什么意思 : +[UAirship executeUnsafeTakeOff:]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21106841/