0
我注意到iOS 10中一個奇怪的推送通知問題。我已經完成了this SO thread的推薦代碼更改以接收推送表單沙箱APNS。iOS 10推送通知 - 沙盒APNS問題
做出這些更改後,我從APNS獲取設備令牌並能夠接收通知。但是,如果我殺了&再次從Xcode啓動應用程序,推送不起作用。如果我從設備上刪除應用程序並將其從Xcode再次放入,則會推動開始。
任何人都看到了這種行爲,並知道可能的修復將是非常有用的。請指教。
這裏是在我的AppDelegate
一步一步實現:
步驟1:導入UserNotifications
#import <UserNotifications/UserNotifications.h>
步驟2:符合通知協議
@interface MyAppDelegate() <UIApplicationDelegate, UNUserNotificationCenterDelegate>
第3步:在application:didFinishLaunchingWithOptions: register for notification
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10")) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
if(!error){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
}
步驟4:最後處理推送通知
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
[self handlePushNotificationWithUserInfo:response.notification.request.content.userInfo];
}
r你註冊了你的設備令牌 –
從來沒有遇到過這個問題。嘗試重置模擬器。 –
我收到推送令牌,交給我的服務器,並在服務器端註冊。他們也發送推送有效載荷。 – Abhinav