iOS Push詳述,了解一下? - 騰訊WeTest - 博客園
如何進行網絡推送
一種是apple自己提供的通知服務(APNS服務器)、一種是用第三方推送
首先在工程中開啟了應用并配有推送證書這時候打開app系統彈出詢問用戶是否允許推送,當用戶允許后向蘋果服務器(APNS)請求deviceToken,并由蘋果服務器發送給自己的應用;自己的應用將DeviceTOken發送自己的服務器;自己服務器想要發送網絡推送時將DeviceToken以及想要推送的信息發送給蘋果服務器,蘋果服務器根據deviceToken將信息發送給對應的客戶端
優點:無論設備開啟與否,都會發送到手機端。缺點是:消息推送的機制是蘋果服務器控制,個別可能會出現推遲。
第三方推送機制,普遍使用Socket機制來實現的,它幾乎可以達到及時的發送到目標用戶手機端,適用于即時通訊類的應用。優點:他幾乎是實時的,主要取決于他心跳包的節奏。缺點:因為ios系統的限制,她不能長時間在后臺運行,所以在應用關閉的情況下這種推送機制是不可用的。
4把程序自己關掉和程序進入后臺,遠程推送的區別
一下來源于:iOS開發 iOS10推送必看 - IOS_Bowen - 博客園
//注冊通知 ?iOS10 iOS8 iOS8以后的不同
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {? ?
if ([[UIDevice currentDevice].systemVersion floatValue]>=10.0) {? ? ? ? UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];? ? ? ?
center.delegate = self;? ? ? ?
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {? ? ? ? ? ?
if (granted) {? ? ? ? ? ? ? ?
NSLog(@"注冊成功");? ? ? ? ? ? ? ?
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { ? ? ? ? ? ? ? ? ? ?
NSLog(@"%@",settings);? ? ? ? ? ? ? ?
}];? ? ? ? ? ?
}else{? ? ? ? ? ? ? ?
NSLog(@"注ceshibai");? ? ? ? ? ?
}? ? ? ? }];?? ? ? ??? ? ? ??
? }else if ([[UIDevice currentDevice].systemVersion floatValue]>8.0 ){? ? ? ? [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];? ?
}else if ([UIDevice currentDevice].systemVersion.floatValue<8.0){? ? ?
?[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];? ?
}? ?? ?
// Override point for customization after application launch.? ?
return YES;}