我正在使用解析API在移動iOS設備之間發送推送通知。但是,當應用程序在後臺時,通知不會到達。我檢查解析SDK iOS - 推送通知僅在應用程序處於前景時纔會顯示
的事情:我的應用程序的
-settings收到通知設置
- 更換背景模式設置
-app功能設置
- 登記的通知是Facebook驗證完成後啓動應用程序時
- (void) authenticateUserWithFacebook {
NSArray *permissionsArray = @[@"user_relationships",@"user_friends",@"read_friendlists",@"publish_actions"];
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
if (!user) {
if (!error) {
NSLog(@"Uh oh. The user cancelled the Facebook login.");
} else {
NSLog(@"Uh oh. An error occurred: %@", error);
[[PFFacebookUtils session] closeAndClearTokenInformation];
[[PFFacebookUtils session] close];
[[FBSession activeSession] closeAndClearTokenInformation];
[[FBSession activeSession] close];
[FBSession setActiveSession:nil];
[PFUser logOut];
[FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) {
NSLog(@"%@",error);
[self authenticateUserWithFacebook];
}];
}
} else if (user.isNew) {
NSLog(@"User with facebook signed up and logged in!");
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[[PFUser currentUser] setObject:[result valueForKey:@"id"] forKey:kFbIdKey];
[[PFUser currentUser] setObject:[result valueForKey:@"name"] forKey:@"name"];
[[PFUser currentUser] saveInBackground];
}];
[self loadUsersFacebookFriends];
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]){
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
} else {
NSLog(@"User with facebook logged in!");
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[[PFUser currentUser] setObject:[result valueForKey:@"id"] forKey:kFbIdKey];
[[PFUser currentUser] setObject:[result valueForKey:@"name"] forKey:@"name"];
[[PFUser currentUser] saveInBackground];
}];
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]){
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge) categories:nil]];
} else{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
}
}];
}
- 註冊委託方法被解僱
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation setObject:[[PFUser currentUser] objectForKey:@"fbId"] forKey:kOwnerKey];
[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error)
NSLog(@"error %@",error);
}];
}
- (void) application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[application registerForRemoteNotifications];
}
-notification委託方法只調用時在前臺
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
- 我也嘗試使用新的配置文件。相同的結果。
- 我從未見過應用程序想要發送通知的彈出式通知。
這隻ios8只是? – 2014-10-26 15:05:45
以及我省略了iOS7部分,只是爲了讓代碼少一點。 – 2014-10-26 15:09:34
plz至少要添加你實際調用registerUserSettings的地方 – 2014-10-26 15:10:59