推送通知在iOS 8上停止工作
我的iOS应用程序停止接收推送通知,尽管我根据文档和 以下是我使用的代码: 在my推送通知在iOS 8上停止工作,ios,parse-platform,ios8,push-notification,Ios,Parse Platform,Ios8,Push Notification,我的iOS应用程序停止接收推送通知,尽管我根据文档和 以下是我使用的代码: 在myAppDelegate的中,使用选项完成启动: if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settin
AppDelegate的中,使用选项完成启动:
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
}
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
// [application registerForRemoteNotifications];
} else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
正在调用didRegisterForRemoteNotificationsWithDeviceToken
方法,就像以前一样,因此一切看起来都很好
此外,我的测试设备已启用通知
但是当从Parse.com
发送推送时,推送不再到达
编辑1:
没有一个答案有效。我将Parse.com框架更新为1.6.2版(最新版本),这也没有帮助,我再次复制我的代码-这次是基于以下答案的更新版本:
内部使用选项完成启动
:
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
}
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
// [application registerForRemoteNotifications];
} else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
以下是委托方法:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken CALLED");
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:newDeviceToken];
[currentInstallation addUniqueObject:@"Test8Channel" forKey:@"channels"];
if([PFUser currentUser]/* && [[PFUser currentUser] objectId] != nil*/) {
[currentInstallation addUniqueObject:[PFUser currentUser] forKey:kOwnerKey];
}
[currentInstallation saveInBackground];
}
#ifdef IS_OS_8_OR_LATER
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[application registerForRemoteNotifications];
NSLog(@"didRegisterUserNotificationSettings CALLED");
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString*)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler {
NSLog(@"handleActionWithIdentifier CALLED");
//handle the actions
if ([identifier isEqualToString:@"declineAction"]){
NSLog(@"handleActionWithIdentifier %@", @"declineAction");
}
else if ([identifier isEqualToString:@"answerAction"]){
NSLog(@"handleActionWithIdentifier %@", @"answerAction");
}
}
#endif
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
if (error.code == 3010) {
NSLog(@"Push notifications are not supported in the iOS Simulator.");
} else {
// show some alert or otherwise handle the failure to register.
NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
}
}
正在调用didRegisterUserNotificationSettings
和didRegisterForRemotionTificationswithDeviceToken
,这两个设置似乎都正常。但推动还没有到来
编辑2:
我注意到如果我两个都打电话
[application registerUserNotificationSettings:settings];
及
在if([application respondsToSelector:@selector(registerUserNotificationSettings:)])中,{
代理的<代码>didRegisterForRemoteNotificationsWithDeviceToken
被调用了两次。我不确定这有多大意义
正在绝望中。/--Set通知
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self enableNotifications:application];
return YES;
}
#define iOS8_OR_NEWER ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 8.0 )
- (void)enableNotifications:(UIApplication *)application
{
if (iOS8_OR_NEWER) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
}
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
// https://nrj.io/simple-interactive-notifications-in-ios-8
}
#endif
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"Push Token : %@", deviceToken);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Failed to get token, error: %@", error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"didReceiveRemoteNotification : %@", userInfo);
}
if([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
//iOS 8通知
[应用程序注册表通知设置:[UIUserNotificationSettings设置类型:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)类别:无];
[申请登记处证明];
}
其他的
{
//iOS<8通知
[应用程序注册信息类型:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
使用这个简单的条件块来处理它。因为有些方法/类是用版本更新的
您是如何从控制台(即,纯文本/json)发送的?您是在后台还是前台等待接收它?我使用默认值,即纯文本,我在后台和前台都尝试过。我还在DidReceiveMemotentification方法中放置了printf,但没有调用它。以及配置文件或证书没有被更改?没有,没有更改。只想做一个快速检查。在转到后台时,检查[[UIApplication sharedApplication]isRegisteredForRemoteNotifications]的结果;并告知结果。我编辑了问题,以反映此处建议后的代码。它仍然不起作用。我编辑了问题,以反映此处建议后的代码。它仍然不起作用。一定是出了问题,如果您在其他Xcode上尝试上述代码,但仍然不起作用,这肯定是设备的问题。您尝试过不同吗ent设备?以上是我得到的唯一代码,并且100%有效。每次我启动我的应用程序时,都会调用所有的方法。“条件块”绝对不是块,在这种情况下甚至不需要块。你的答案与所有其他答案完全相同,只是代码增加了10倍。。。
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
//ios8
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
.......
}
}
else
{
// ios7
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotificationTypes:)])
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
.........
}
}