我试图在我的iOS应用程序中使用解析通知,我一步一步地按照parse.com网站上的指南进行操作,但它仍然不起作用,这是我的app delegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Parse enableLocalDatastore];
// Initialize Parse.
[Parse setApplicationId:@"XXXXXXXXXXXX"
clientKey:@"XXXXXXXXXXX"];
// [Optional] Track statistics around application opens.
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
NSLog(@"START");
// Register for Push Notitications
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
[self grabStoryboard];
[FBLoginView class];
[FBProfilePictureView class];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}
- (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);
}
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}
在parse.com上,我看到我已经注册了1台设备,但是当我点击&#34;发送推送&#34;发送的推送是0
答案 0 :(得分:0)
您应该检查Parse上的App设置。转到推送通知,看看您是否上传了正确的证书(Apple推送证书)。这应该可以解决你的问题。
答案 1 :(得分:0)
将此添加到远程通知部分的did寄存器中。
[currentInstallation setObject:[PFUser currentUser].objectId forKey:@"owner"];
以及发送推送的位置添加此
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"owner" containedIn:self.recipients];
如果这不起作用,请告诉我您发送推送的方法