官方文檔地址:非常詳細(xì),按步驟 so easy
http://docs.jpush.io/guideline/ios_guide/
極光默認(rèn)的推送后臺(tái)
https://www.jpush.cn/common/apps
- 1 開發(fā)者中心申請推送證書俗慈,并且需要 p12 文件
- 2 按文檔說明導(dǎo)入必要文件與框架
- 3 復(fù)制代碼
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 注冊
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//可以添加自定義categories iOS8 新特性弟塞,例如快速回復(fù)
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories 必須為nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
[JPUSHService setupWithOption:launchOptions appKey:@"appkey"
channel:@"appstore"
apsForProduction:NO // 如果為開發(fā)狀態(tài),設(shè)置為 NO; 如果為生產(chǎn)狀態(tài),應(yīng)改為 YES.
advertisingIdentifier:nil];// 廣告 不用設(shè)置為nil
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
/// Required - 注冊 DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// 收到通知就觸發(fā)
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
[JPUSHService resetBadge]; // 重置 腳標(biāo)
// 處理 userinfo
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
// error 處理
}
4 其他高級功能好像并不是很多用
5 如果需要,可以研究以下 iOS8 的新特性 UIUserNotificationSettings 對通知的便捷操作。
1