JPush - 极光推送
2016-04-20 本文已影响354人
居然是村长
官方文档地址:非常详细,按步骤 so easy
http://docs.jpush.io/guideline/ios_guide/
极光默认的推送后台
https://www.jpush.cn/common/apps
- 1 开发者中心申请推送证书,并且需要 p12 文件
- 2 按文档说明导入必要文件与框架
- 3 复制代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 注册
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//可以添加自定义categories iOS8 新特性,例如快速回复
[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 // 如果为开发状态,设置为 NO; 如果为生产状态,应改为 YES.
advertisingIdentifier:nil];// 广告 不用设置为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 {
// 收到通知就触发
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
[JPUSHService resetBadge]; // 重置 脚标
// 处理 userinfo
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
// error 处理
}
-
4 其他高级功能好像并不是很多用
-
5 如果需要,可以研究以下 iOS8 的新特性 UIUserNotificationSettings 对通知的便捷操作。
1