註冊推送通知的常用方法是在Appdelegate中添加以下代碼。是否需要在註冊apns推送通知時檢查互聯網連接
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
如果沒有互聯網連接,會發生什麼?當互聯網連接回來時,應用程序是否會嘗試自動註冊推送通知?
是必要的檢查互聯網連接和註冊的推送通知,如以下
if ([wifiConnection wifiConnectivity]){
if (![[NSUserDefaults standardUserDefaults] stringForKey:@"MyAppSpecificGloballyUniqueString"]) {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
}
此外,如果我們將它添加到應用程序變爲活動前已經註冊的條件 - 它會按預期希望。
請確認。