我尝试设置 Urban Airship 以向我的 iOS 应用程序发送推送通知,但没有成功。
这是我的东西:
- 启用推送通知的开发人员配置文件
- 在设备上推送通知证书并上传到 Urban Airship
- 任何地方都没有错误 - UA 的错误控制台是空的,我检查了我的设备 token 是否处于事件状态
这是我的 AppDelegate.m 文件中的一些片段
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];
//Init Airship launch options
NSMutableDictionary *takeOffOptions = [[NSMutableDictionary alloc] init];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
// Create Airship singleton that's used to talk to Urban Airship servers.
// Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
[UAirship takeOff:takeOffOptions];
// Register for notifications
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
[UAirship setLogging:YES];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
// Updates the device token and registers the token with UA
NSLog(@"APN device token: %@", devToken);
[[UAPush shared] registerDeviceToken:devToken];
}
当我通过 UA 的“测试推送通知”选项卡发送通知或通过终端发送 CURL 命令时,以下方法均未被调用
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(@"Error in registration. Error: %@", err.description);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Received push notification with userInfo:%@", userInfo);
}
- (void)handleNotification:(NSDictionary *)notification applicationState:(UIApplicationState)state
{
NSLog(@"Received push notification with notification:%@", notification);
}
我曾尝试在关闭应用程序的情况下发送测试推送通知,但 iOS 也没有执行任何操作。我检查了 iphone 上的设置并转到我的应用程序,它显示已为角标(Badge)和横幅启用推送。我在 iPhone 5 上运行 iOS 6.1。
最佳答案
我想通了 - 我一定是错过了文档中的这一行:
[[UAPush shared] handleNotification:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]
applicationState:application.applicationState];
关于ios - iOS 设备未收到 Urban Airship iOS 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14761755/