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
相關文章
- iOS 推送(蘋果原生態)iOS蘋果
- [混編] iOS原生專案- 接入FlutteriOSFlutter
- APP接入友盟統計,不上報資料問題APP
- 友盟umeng訊息推送直接複製就能用(純乾貨)
- 友盟+:2021年度APP訊息推送白皮書(附下載)APP
- ReactNative版友盟推送React
- iOS 本地推送iOS
- 實現友盟分享
- iOS 推送通知及推送擴充套件iOS套件
- 原生Android工程接入Flutter aarAndroidFlutter
- 在iOS上接入TensorflowiOS
- MUI接入個推推送與後臺聯調UI
- React Native 結合友盟實現分享React Native
- iOS 10 的推送 User Notifications FrameworkiOSFramework
- 玩轉 iOS 10 推送 —— UserNotifications Framework(中)iOSFramework
- iOS推送系列之Push的工作原理iOS
- iOS12中推送通知新特性iOS
- iOS —— 極光推送和極光IMiOS
- 玩轉 iOS 10 推送 —— UserNotifications Framework(上)iOSFramework
- 玩轉 iOS 10 推送 —— UserNotifications Framework(下)iOSFramework
- Flutter 混合開發FlutterBoost iOS 接入流程FlutteriOS
- 對友盟分享(Umeng-Share)的功能封裝封裝
- iOS原生彈框框架-TRCustomAlertiOS框架
- iOS原生 VS Flutter評測iOSFlutter
- 極光推送申請iOS推送證書p12及配置流程iOS
- 極光推送申請iOS推送證書p12及配置教程iOS
- iOS怎麼推送統計到達率iOS
- iOS微信支付接入以及工具類封裝iOS封裝
- Python接入企業微信 - 推送資訊到內部群裡Python
- Android 友盟社會化分享的整合與封裝Android封裝
- 如何把原生程式碼推送到遠端倉庫
- Flutter 與 iOS 原生 WebView 對比FlutteriOSWebView
- ReactNative 踩坑之 iOS 原生元件ReactiOS元件
- Dubbo 3.1.0 正式釋出,資料面原生接入 Service Mesh
- 蘋果iOS 12原生相簿使用教程 蘋果iOS 12原生相簿怎麼用?蘋果iOS
- 長連線資料實時推送方案(iOS)iOS
- 極光筆記丨iOS 15推送新特性筆記iOS
- Ruff裝置接入阿里雲IoT平臺推送告警到釘釘群阿里