极光推送JPush --- 简单使用
2017-06-06 11:54
393 查看
一般的APP都会有推送功能,来增加用户粘性,而极光的JPush是个不错的三方。
我用cocoaPods安装 pod 'JPush'
然后在AppDelegate.m文件里
还有就是:::
我用cocoaPods安装 pod 'JPush'
然后在AppDelegate.m文件里
#import "AppDelegate.h" // 引入JPush功能所需头文件 #import "JPUSHService.h" // iOS10注册APNs所需头文件 #ifdef NSFoundationVersionNumber_iOS_9_x_Max #import <UserNotifications/UserNotifications.h> #endif @interface AppDelegate ()<JPUSHRegisterDelegate> @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;//电池栏 /* * 添加极光 */ [self addJPUSHRegister:launchOptions]; return YES; } -(void)addJPUSHRegister:(NSDictionary*)launchOptions{ //Required //notice: 3.0.0及以后版本注册可以这样写,也可以继续用之前的注册方式 JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { // 可以添加自定义categories // NSSet<UNNotificationCategory *> *categories for iOS10 or later // NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9 } [JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; // Required // init Push // notice: 2.1.5版本的SDK新增的注册方法,改成可上报IDFA,如果没有使用IDFA直接传nil // 如需继续使用pushConfig.plist文件声明appKey等配置内容,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。 [JPUSHService setupWithOption:launchOptions appKey:@"7937fbbb35fc010bad2f11a7" channel:nil apsForProduction:NO advertisingIdentifier:nil]; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { //注册APNs成功并上报DeviceToken /// Required - 注册 DeviceToken [JPUSHService registerDeviceToken:deviceToken]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { //Optional实现注册APNs失败接口(可选) NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error); } #pragma mark- JPUSHRegisterDelegate // iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler { // Required NSDictionary * userInfo = notification.request.content.userInfo; if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [JPUSHService handleRemoteNotification:userInfo]; } completionHandler(JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置 } // iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { // Required NSDictionary * userInfo = response.notification.request.content.userInfo; if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [JPUSHService handleRemoteNotification:userInfo]; } completionHandler(); // 系统要求执行这个方法 } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { // Required, iOS 7 Support [JPUSHService handleRemoteNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { // Required,For systems with less than or equal to iOS6 [JPUSHService handleRemoteNotification:userInfo]; } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.(App即将进入前台)中将小红点清除 NSLog(@"进入前台"); [UIApplication sharedApplication].applicationIconBadgeNumber = 0; }
还有就是:::
//注册极光别名和标签 NSSet *t b24d ags =[NSSet setWithObjects:@"old",@"all",@"new", nil]; [JPUSHService setTags:tags alias:@"userID" fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) { }];
相关文章推荐
- 极光推送 JPush 项目简单使用
- 极光推送Jpush之RestAPI使用实例
- Android JPush(极光推送)的使用教程
- android 高级之旅 (八) 极光推送 JPush 的基本使用
- jpush极光推送平台的使用
- ionic 之cordova 极光推送jpush和百度定位插件结合使用之定位失效问题解决办法
- JPush手机APP推送简单总结-极光
- Android JPush(极光推送)的使用教程
- Swift - JPush极光推送的使用4(根据Tag标签,给同一类别用户发推送)
- 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
- JPush极光推送的原理与简单demo的实现会遇到的问题
- 关于"极光"APP推送JPUSH的服务器端使用
- C#简单的JPush(极光推送) API实现推送功能
- ios app 推送功能 JPush极光推送的使用
- Android JPush(极光推送)的使用教
- [iOS APNs极光推送] APNs证书+极光推送+简单使用+仅开发环境
- php使用JPush极光推送ios android通知消息
- Swift - JPush极光推送的使用3(根据Alias别名,给某个指定用户发推送)(转)
- 极光推送使用心得(简单使用)
- 使用Jpush(极光推送)实现推送功能