日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

JPush 使用教程

發布時間:2023/12/1 综合教程 46 生活家
生活随笔 收集整理的這篇文章主要介紹了 JPush 使用教程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

JPush 使用教程

自己使用的一些經驗,為了方便直接從這里復制過去就行。
就當做個筆記,防止長時間忘記之后,還需要去官網看文檔。

主要思路: sdk文件 + 三方依賴系統庫 + 頭文件 + 添加代理 + 初始化代碼

1.版本信息

  • JPush : 2.2.0
  • Xcode : 8.3.3
  • iOS : 6.0 +

2.使用步驟

  • 導入頭文件
#import "JPUSHService.h"
// iOS10注冊APNs所需頭文件
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#endif
  • 添加如下代碼(支持版本為 iOS 6.0+)
#pragma mark -- JPush/**注冊apns*/
- (void)registerAPNSWithOptions:(NSDictionary *)launchOptions{//Required//notice: 3.0.0及以后版本注冊可以這樣寫,也可以繼續用之前的注冊方式JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;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:@"2c6034060b406cfe94d4e2e2"channel:@"App Store"apsForProduction:YESadvertisingIdentifier:nil];NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];[defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];}
/**極光推送消息處理@param notification 極光推送通知*/
- (void)networkDidReceiveMessage:(NSNotification *)notification {NSDictionary * userInfo = [notification userInfo];NSString *content = [userInfo valueForKey:@"content"];NSDictionary *extras = [userInfo valueForKey:@"extras"];NSString *customizeField1 = [extras valueForKey:@"customizeField1"]; //服務端傳遞的Extras附加字段,key是自己定義的}- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {/// Required - 注冊 DeviceToken[JPUSHService registerDeviceToken:deviceToken];
}#pragma mark- JPUSHRegisterDelegate// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {// RequiredNSDictionary * userInfo = notification.request.content.userInfo;if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {[JPUSHService handleRemoteNotification:userInfo];}completionHandler(UNNotificationPresentationOptionAlert); // 需要執行這個方法,選擇是否提醒用戶,有Badge、Sound、Alert三種類型可以選擇設置
}// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {// RequiredNSDictionary * 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 {NSString *content = [userInfo valueForKey:@"content"];NSDictionary *extras = [userInfo valueForKey:@"extras"];NSString *customizeField1 = [extras valueForKey:@"customizeField1"];NSLog(@"content --- %@",content);NSLog(@"extras --- %@",extras);NSLog(@"customizeField1 --- %@",customizeField1);// 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];
}#pragma mark -- JPush
  • 添加依賴庫文件

3.其他配置

  • 在 JPush 官網注冊應用,記住對應的Appkey,

代碼中注冊的時候使用。

  • 證書配置

直接導出調試推送證書 和 發布推送證書 的 .12 文件上傳到JPush 官網。

  • 開放App的后臺能力 和 推送能力

JPush 官網: https://www.jiguang.cn/accounts/login/form

官方iOS SDK 集成指南:https://docs.jiguang.cn/jpush/client/iOS/ios_guide_new/

轉載于:https://www.cnblogs.com/xiaoyouPrince/p/7249970.html

總結

以上是生活随笔為你收集整理的JPush 使用教程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。