我似乎已经使用解析网站上的指南正确设置了所有内容以集成推送通知,但是几天后我无法理解为什么我的设备从内部发送时不会收到通知应用程序,但在从解析仪表板发送全局通知时会收到它们。在App委托:
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
和
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *nameStrng = [defaults objectForKey:@"name"];
[currentInstallation setObject:nameStrng forKey:@"username"];
[currentInstallation saveInBackground];
}
在_Installations中为设备指定名称。使用
创建实际推送通知-(void)sendPush{
NSArray* array =[[NSArray alloc]initWithArray:questionArray[cardNumber-1]];
PFQuery *pushQuery = [PFInstallation query];
NSString *nameForPush=array[1];
[pushQuery whereKey:@"username" equalTo:nameForPush];
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
[push setMessage:@"Hello World!"];
[push sendPushInBackground];
}
发送此通知后,在Parse Push Notifications Dashboard中,它会将通知标记为发送到1个设备(我正在运行应用程序的设备)但它永远不会到达。我已经尝试重复所有步骤来配置推送通知,包括新证书和配置文件,但没有任何帮助,所以如果有人有任何建议会很好。