【发布时间】:2014-12-17 05:41:55
【问题描述】:
我的应用程序包含推送通知功能,我已完成编码部分以在我的应用程序中接收推送通知。当我的应用程序进入后台时,我正在接收推送通知,当我单击推送通知按钮时,应用程序进入前台并调用接收远程通知委托方法。当我的应用在后台收到推送通知但没有通过单击屏幕顶部的推送通知按钮打开应用时,我需要调用相同的委托方法。我编写了如下代码。
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings
settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
}
else
{
// Register for Push Notifications, if running iOS version < 8
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge
|UIUserNotificati
onTypeSound categories:nil]];
}
我的最终意图是调用确实在应用程序处于后台时收到远程通知。
【问题讨论】:
标签: objective-c iphone apple-push-notifications