【问题标题】:iOS 8 Push notification does not work on real deviceiOS 8 推送通知在真实设备上不起作用
【发布时间】:2015-04-09 10:47:23
【问题描述】:

我有一个应用程序,我想将 APN 与 iOS 推送通知一起使用。我的推送通知与 ios 8 及更低版本兼容。当我在模拟器上启动时,推送通知权限对话框正常工作。但是在真实设备中启动时会显示;

“正在尝试标记应用程序图标但未收到 用户授予应用程序徽章的权限”

AppDelegate

[[NotificationManager sharedInstance] requestPushNotificationIfNeeded];

NotificationManager - requestPushNotificationIfNeeded

// Refresh the token.
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
    if([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]){
        // iOS 8 Notification
        UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
    }
    else {
        // Less then iOS 8
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         UIRemoteNotificationTypeAlert |
         UIRemoteNotificationTypeBadge |
         UIRemoteNotificationTypeSound];
    }
#else
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     UIRemoteNotificationTypeAlert |
     UIRemoteNotificationTypeBadge |
     UIRemoteNotificationTypeSound];
#endif

应用委托方法

#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:   (UIUserNotificationSettings *)notificationSettings
{
    TRACE(@"Delegate did");
    //register to receive notifications
    [application registerForRemoteNotifications];
}
#endif

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    // Using parse.com save push notification token
}

问题

这段代码有什么问题?我尝试了几天但徒劳无功。你能指导我这个错误吗?有什么问题还是我错过了一些必要的东西?非常感谢。


顺便说一句,我退出委托方法只注册 UIUserNotificationTypeAlert 像这样;

Delegate didRegisterUserNotificationSettings: <UIUserNotificationSettings: 0x17422e2c0; types: (UIUserNotificationTypeAlert);> 

【问题讨论】:

  • 你的设备iOS版本是多少?
  • @TENSRI 应用现在在 iOS 8.2 上运行
  • 据我所知,一切都很好,您可以尝试删除应用程序并重新安装或清理项目中的构建......
  • 你在Project Capabilities中开启远程通知了吗??
  • @kayzersoze 你能在这里粘贴你推送通知委托方法吗?

标签: ios objective-c push-notification


【解决方案1】:

您的应用似乎没有正确的permissions 来生成push notifications
根据苹果在这种情况下的建议,我曾经也必须遵循。请按以下步骤操作:
1) 卸载应用,然后重启手机。
2) 转到设置 -> 日期和时间,并将日期设置为至少比当前日期提前 1 天。
3) 再次重启您的设备。
4) 现在进入设置,让时间恢复正常。
5) 重启设备。 6) 现在安装应用程序,它应该会询问您推送通知的权限。如果它仍然不要求权限,请再次重复上述步骤,但在第 4 步之后而不是重新启动,只需安装应用程序然后重新启动,您就可以开始了。
我希望这能解决您的问题。

【讨论】:

  • 谢谢。但这并没有解决我的问题:/这个错误让我哭泣!
  • 为了获得推送通知,您必须首先获得用户的许可。如果在应用程序启动的第一次运行时没有询问权限,那么您必须先尝试获取权限。
  • 我知道这些步骤,它在模拟器上完美运行,但万一启动真实设备时它什么也没问。当我想首先在模拟器上运行应用程序时,我点击了左上角的iOS Simulator 菜单,然后点击了Reset Contents and Settings... 就可以了。通知有效。但是当我进入真实设备时。轰轰烈烈。
  • 您认为我也应该尝试这些步骤吗? support.apple.com/en-ae/HT201274
猜你喜欢
  • 2016-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多