IOS原生接入友盟推送
一、cocapad 匯入友盟三方庫
pod 'UMCCommon'
pod 'UMCSecurityPlugins'
pod 'UMCPush'
二、AppDelegate.m配置
- (void)configurationUM:(NSDictionary *)launchOptions{
[UMConfigure setLogEnabled:YES];
[UMConfigure initWithAppkey:@"" channel:@"appstore"];
[UMessage setBadgeClear:NO];
// Push元件基本功能配置
UMessageRegisterEntity * entity = [[UMessageRegisterEntity alloc] init];
//type是對推送的幾個引數的選擇,可以選擇一個或者多個。預設是三個全部開啟,即:聲音,彈窗,角標
entity.types = UMessageAuthorizationOptionBadge|UMessageAuthorizationOptionSound|UMessageAuthorizationOptionAlert;
[UNUserNotificationCenter currentNotificationCenter].delegate=self;
[UMessage registerForRemoteNotificationsWithLaunchOptions:launchOptions Entity:entity completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
}else{
}
}];
NSString*Alias
//繫結別名
[UMessage addAlias: Alias type:@"qiangdan" response:^(id _Nonnull responseObject, NSError * _Nonnull error) {
NSString* str = [NSString stringWithFormat:@"%@",responseObject];
}];
}
//iOS10新增:處理前臺收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[UMessage setAutoAlert:NO];
//必須加這句程式碼
[UMessage didReceiveRemoteNotification:userInfo];
NSLog(@"%s--%@",__func__,userInfo);
}else{
//應用處於前臺時的本地推送接受
}
completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
}
//iOS10新增:處理後臺點選通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//必須加這句程式碼
[UMessage didReceiveRemoteNotification:userInfo];
NSLog(@"%s--%@",__func__,userInfo);
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken %@",deviceToken);
if (!deviceToken || [deviceToken length] == 0) {
return;
}
NSMutableString *string = [[NSMutableString alloc] initWithCapacity:[deviceToken length]];
[deviceToken enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop) {
unsigned char *dataBytes = (unsigned char*)bytes;
for (NSInteger i = 0; i < byteRange.length; i++) {
NSString *hexStr = [NSString stringWithFormat:@"%x", (dataBytes[i]) & 0xff];
if ([hexStr length] == 2) {
[string appendString:hexStr];
} else {
[string appendFormat:@"0%@", hexStr];
}
}
}];
NSLog(@"deviceToken string %@",string);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"error %@",error.localizedDescription);
}
三、與後端進行聯調推送
3.1在友盟後臺進行真機除錯,在後臺建立一個推送訊息模組
下一步:
最後一步:
就可以在真機除錯獲得推送訊息;
3.2與後臺小哥哥除錯推送
這就需要在友盟後臺配置IP白名單也就是推送伺服器的IP
app需要打包成AdHoc模式安裝才能進行除錯
四、總結
多看文件 與後臺小哥哥一起合作完成該功能
參考資料:
https://developer.umeng.com/docs/119267/detail/119510
相關文章
- Swift 整合友盟推送Swift
- IOS 友盟iOS
- iOS 推送(蘋果原生態)iOS蘋果
- IOS 友盟 閃退 追蹤方法iOS
- APP接入友盟統計,不上報資料問題APP
- [混編] iOS原生專案- 接入FlutteriOSFlutter
- swift3 友盟推送獲取deviceTocken 列印為32 bytesSwiftdev
- 友盟+:2021年度APP訊息推送白皮書(附下載)APP
- 友盟iOS微信登陸沒有回撥的原因iOS
- 實現友盟分享
- 接入友盟第三方登入與分享,判斷應用是否安裝
- ReactNative版友盟推送React
- 極光推送—java快速接入Java
- 友盟分享 Twitter遇到的坑
- 【友盟+】推送Android SDK 3.0釋出,一次拯救訊息到達率的迭代Android
- iOS推送之本地推送iOS
- iOS推送之遠端推送iOS
- 原生Android工程接入Flutter aarAndroidFlutter
- iOS 本地推送iOS
- iOS 推送整理iOS
- ios中推送iOS
- iOS友盟崩潰地址解析 通過dSYM檔案分析定位線上 APP crash問題iOSAPP
- React Native 結合友盟實現分享React Native
- 小米殺不死的推送-- Android、java後端同時接入小米推送AndroidJava後端
- iOS 推送通知及推送擴充套件iOS套件
- IOS 蘋果官方推送iOS蘋果
- iOS推送機制iOS
- MUI接入個推推送與後臺聯調UI
- 對友盟分享(Umeng-Share)的功能封裝封裝
- 【友盟+】李丹楓:DI,資料賦予智慧力量
- 【友盟+】COO葉謙:全域資料 智慧未來
- 如何填補友盟分享新浪微博的那些坑
- 在iOS上接入TensorflowiOS
- iOS推送——本地推送與遠端推送詳解(一圖看懂)iOS
- iOS本地通知(推送)iOS
- 在友盟分享的基礎上整合微信登入
- xcode9 pod update後友盟build不過XCodeUI
- iOS 接入百度雲推送"error_code" = 10002; 網路部可用問題iOSError