項目中因為好多地方要使用到通知,對比了好幾個推送的sdk,最后還是選擇了極光推送,從穩(wěn)定性和集成方便來說,那是沒問題的
極光推送 官網
文檔地址: https://docs.jiguang.cn/jpush/client/iOS/ios_sdk/
注冊完賬號,添加應用,配置對應的開發(fā)環(huán)境和生產環(huán)境的p12證書,APP集成完畢之后,就可以通過控制臺發(fā)送通知測試集成是否成功,如果是高峰期,極光推送可能會有一定的延遲,20分鐘左右都是正常的,耐心等待一些
下面是APP啟動初始化sdk的代碼
-(void)registerRemoteWithOptions:(NSDictionary *)launchOptions
{
//Required
//notice: 3.0.0及以后版本注冊可以這樣寫雄人,也可以繼續(xù)用之前的注冊方式
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
if (IOS8) {
// 可以添加自定義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
// 如需繼續(xù)使用pushConfig.plist文件聲明appKey等配置內容,請依舊使用[JPUSHService setupWithOption:launchOptions]方式初始化。
[JPUSHService setupWithOption:launchOptions appKey:JPushAppKey
channel:@"App Store"
apsForProduction:isProduction
advertisingIdentifier:nil];
//2.1.9版本新增獲取registration id block接口。
[JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
if(resCode == 0){
NSLog(@"registrationID獲取成功:%@",registrationID);
}
else{
NSLog(@"registrationID獲取失敗干毅,code:%d",resCode);
}
}];
}
控制臺推送的時候,如果APP角標不自增,是推送的時候把badge 一直默認為 1 了,應該設置為 +1
如果是想推送給自己服務器的某個用戶,需要服務器那邊對接并且在登錄的時候,返回一個當前用戶的id,專門用來推送給某個用戶的,
[JPUSHService setAlias:[NSString stringWithFormat:@"%@",user_id] callbackSelector:nil object:nil];