概述
MobPush 注冊推送,獲取推送id等方法均可在SDK的"MobPush.h"中進(jìn)行查看,也可以下載MobPush的Demo進(jìn)行參考。
推送環(huán)境設(shè)置(setAPNsForProduction)
/**
@param isProduction 是否生產(chǎn)環(huán)境。 如果為開發(fā)狀態(tài),設(shè)置為 NO; 如果為生產(chǎn)狀態(tài),應(yīng)改為 YES。 Default 為 YES 生產(chǎn)狀態(tài)
*/
+ (void)setAPNsForProduction:(BOOL)isProduction;
示例代碼
// 設(shè)置推送環(huán)境
#ifdef DEBUG
[MobPush setAPNsForProduction:NO];
#else
[MobPush setAPNsForProduction:YES];
#endif
注冊推送配置(setupNotification)
/**
@param configuration 配置信息
*/
+ (void)setupNotification:(MPushNotificationConfiguration *)configuration;
示例代碼
//MobPush推送設(shè)置(獲得角標(biāo)、聲音、彈框提醒權(quán)限),應(yīng)用要收到推送(角標(biāo)、聲音、彈框提醒)需要先申請權(quán)限,這個(gè)方法就是設(shè)置推送配置、申請權(quán)限的方法。用法可參考以下的例子。
MPushNotificationConfiguration *configuration = [[MPushNotificationConfiguration alloc] init];
configuration.types = MPushAuthorizationOptionsBadge | MPushAuthorizationOptionsSound | MPushAuthorizationOptionsAlert;
[MobPush setupNotification:configuration];
通知回調(diào)接口(MobPushDidReceiveMessageNotification)
/**
收到消息通知(數(shù)據(jù)是MPushMessage對象,可能是推送數(shù)據(jù)、自定義消息數(shù)據(jù),APNs、本地通知等的回調(diào))
*/
extern NSString *const MobPushDidReceiveMessageNotification;
說明:應(yīng)用收到消息事,MobPush會(huì)發(fā)起一個(gè)通知,開發(fā)者只需要建立一個(gè)通知收聽 MobPushDidReceiveMessageNotification 并作相應(yīng)處理即可。收到的數(shù)據(jù)是一個(gè)MPushMessage對象,可能是推送數(shù)據(jù),也可能是自定義消息數(shù)據(jù)。如果是推送數(shù)據(jù),開發(fā)者可以通過MobPush.h中的addLocalNotification:方法,讓消息以本地通知形式顯示(iOS 10之前的系統(tǒng)應(yīng)用內(nèi)是不會(huì)顯示通知的)。
示例代碼
// 注冊通知回調(diào)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMessage:) name:MobPushDidReceiveMessageNotification object:nil];
//查看通知參數(shù)可以打印notification
- (void)didReceiveMessage:(NSNotification *)notification{}
獲取推送RegistrationID (getRegistrationID)
獲取推送RegistrationID接口,RegistrationID可與用戶id綁定,實(shí)現(xiàn)向指定用戶推送消息,此接口必須在推送設(shè)置接口之后調(diào)用。
/**
獲取注冊id(可與用戶id綁定,實(shí)現(xiàn)向指定用戶推送消息)
@param handler 結(jié)果
*/
+ (void)getRegistrationID:(void(^)(NSString *registrationID, NSError *error))handler;
示例代碼
[MobPush getRegistrationID:^(NSString *registrationID, NSError *error) {
NSLog(@"registrationID = %@--error = %@", registrationID, error);
}];
推送標(biāo)簽API(addTags)
MobPush支持根據(jù)標(biāo)簽進(jìn)行推送,所以也提供了對標(biāo)簽的相應(yīng)操作。
/**
獲取所有標(biāo)簽
@param handler 結(jié)果
*/
+ (void)getTagsWithResult:(void (^) (NSArray *tags, NSError *error))handler;/**
/**
添加標(biāo)簽
@param tags 標(biāo)簽組
@param handler 結(jié)果
*/
+ (void)addTags:(NSArray *)tags result:(void (^) (NSError *error))handler;
/**
刪除標(biāo)簽
@param tags 需要?jiǎng)h除的標(biāo)簽
@param handler 結(jié)果
*/
+ (void)deleteTags:(NSArray *)tags result:(void (^) (NSError *error))handler;
/**
清空所有標(biāo)簽
@param handler 結(jié)果
*/
+ (void)cleanAllTags:(void (^) (NSError *error))handler;
示例代碼
[MobPush getTagsWithResult:^(NSArray *tags, NSError *error) {};
[MobPush addTags:[self tags] result:^(NSError *error) {};
[MobPush deleteTags:[self tags] result:^(NSError *error) {};
[MobPush cleanAllTags:^(NSError *error) {};
推送別名API(setAlias)
MobPush同樣支持根據(jù)別名推送,所以也提供了對別名的相應(yīng)操作。
/**
獲取別名
@param handler 結(jié)果
*/
+ (void)getAliasWithResult:(void (^) (NSString *alias, NSError *error))handler;
/**
設(shè)置別名
@param alias 別名
@param handler 結(jié)果
*/
+ (void)setAlias:(NSString *)alias result:(void (^) (NSError *error))handler;
/**
刪除別名
@param handler 結(jié)果
*/
+ (void)deleteAlias:(void (^) (NSError *error))handler;
示例代碼
[MobPush getAliasWithResult:^(NSString *alias, NSError *error) {
};
[MobPush deleteAlias:^(NSError *error) {
};
[MobPush setAlias:@"alias" result:^(NSError *error) {
}];
添加本地推送接口(addLocalNotification)
/**
添加本地推送通知
@param request 消息請求(消息標(biāo)識(shí)、消息具體信息、觸發(fā)方式)
@param handler 結(jié)果,iOS10以上成功result為UNNotificationRequest對象、iOS10以下成功result為UILocalNotification對象,失敗result為nil
*/
+ (void)addLocalNotification:(MPushNotificationRequest *)request result:(void (^) (id result, NSError *error))handler;
示例代碼
#import
[MobPush addLocalNotification:request result:^(id result, NSError *error) {};
設(shè)置角標(biāo)(setBadge)
/**
設(shè)置角標(biāo)值到Mob服務(wù)器
本地先調(diào)用setApplicationIconBadgeNumber函數(shù)來顯示角標(biāo),再將該角標(biāo)值同步到Mob服務(wù)器,
@param badge 新的角標(biāo)值(會(huì)覆蓋服務(wù)器上保存的值)
*/
+ (void)setBadge:(NSInteger)badge;
/**
清除角標(biāo),但不清空通知欄消息
*/
+ (void)clearBadge;
示例代碼
[MobPush setBadge:8];
[MobPush clearBadge];
打開和關(guān)閉遠(yuǎn)程推送(stopPush)
/**
關(guān)閉遠(yuǎn)程推送(應(yīng)用內(nèi)推送和本地通知不受影響,只關(guān)閉遠(yuǎn)程推送)
*/
+ (void)stopPush;
/**
打開遠(yuǎn)程推送
*/
+ (void)restartPush;
示例代碼
[MobPush stopPush];
[MobPush restartPush];
應(yīng)用處于前臺(tái)時(shí)設(shè)置推送消息的提示類型(setAPNsShowForegroundType)
/**
設(shè)置應(yīng)用在前臺(tái)有 Badge、Sound、Alert 三種類型,默認(rèn)3個(gè)選項(xiàng)都有,iOS 10 以后設(shè)置有效。
如果不想前臺(tái)有 Badge、Sound、Alert,設(shè)置 MPushAuthorizationOptionsNone
@param type 類型
*/
+ (void)setAPNsShowForegroundType:(MPushAuthorizationOptions)type;
示例代碼
//設(shè)置后,應(yīng)用在前臺(tái)時(shí)不展示通知橫幅、角標(biāo)、聲音。(iOS 10 以后有效,iOS 10 以前本來就不展示)
[MobPush setAPNsShowForegroundType:MPushAuthorizationOptionsNone];
指定刪除收到的本地推送(removeNotificationWithIdentifiers)
/**
刪除指定的推送通知(可以刪除未發(fā)送或者已經(jīng)發(fā)送的本地通知)
@param identifiers 推送請求標(biāo)識(shí)數(shù)組,為nil,刪除所有通知
*/
+ (void)removeNotificationWithIdentifiers:(NSArray *)identifiers;
示例代碼
[MobPush removeNotificationWithIdentifiers:nil];
推送打開指定應(yīng)用內(nèi)指定頁面(initWithMobPushScene)
后臺(tái)配置
如果開發(fā)者想要對通知消息進(jìn)行點(diǎn)擊跳轉(zhuǎn)到app內(nèi)指定頁面的操作,可以在開發(fā)者管理后臺(tái)打開配置開關(guān)和參數(shù)設(shè)置。

Scheme地址:為開發(fā)者自定義的控制器路徑。
傳遞參數(shù):為跳轉(zhuǎn)控制器的初始化參數(shù)。
代碼配置
開發(fā)者需要在自己的應(yīng)用內(nèi)對所跳轉(zhuǎn)的控制器進(jìn)行相關(guān)代碼設(shè)置。如下:(可參照demo中PushViewController.m) 參考鏈接(可參考示例代碼也可以參考鏈接去設(shè)置): https://www.jianshu.com/p/9abb125b5456
/**
設(shè)置控制器路徑
@return 控制器路徑
*/
+ (NSString *)MobPushPath;
/**
初始化場景參數(shù)
@param params 場景參數(shù)
@return 控制器對象
*/
- (instancetype)initWithMobPushScene:(NSDictionary*)params;
示例代碼
#import
// 還原標(biāo)識(shí)ios可以自定義在對應(yīng)vc中實(shí)現(xiàn)如下還原代碼
+ (NSString *)MobPushPath
{
return @"mlink://com.mob.mobpush.link";
}
//點(diǎn)擊推送場景還原頁面參數(shù)
- (instancetype)initWithMobPushScene:(NSDictionary *)params
{
if (self = [super init])
{
}
return self;
}
富媒體推送使用(MobPushServiceExtension)
添加 MobPushServiceExtension 依賴庫

設(shè)置 Notification Service 最低運(yùn)行版本為 10.0:
開啟富媒體地址Http訪問支持

使用 MobPushServiceExtension 進(jìn)行富媒體推送
在 NotificationService.m 文件中,導(dǎo)入 MobPushServiceExtension 的頭文件:
#import
進(jìn)入MobPush開發(fā)者后臺(tái)通過url(帶有后綴格式的文件地址)或者文件的方式發(fā)送富媒體通知。(必須勾選mutable-content選項(xiàng))
調(diào)用handelNotificationServiceRequestUrl方法。接收到 APNs 通知后,SDK 判斷是否有富媒體資源request.content.userInfo[@“attachment”],如果富媒體資源存在則SDK下載資源,下載完成后以 Block 方式回調(diào)返回 attachments 資源數(shù)組對象和error錯(cuò)誤信息。
示例代碼
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
#pragma mark ----將APNs信息交由MobPush處理----
NSString * attachUrl = request.content.userInfo[@“attachment”];
[MobPushServiceExtension handelNotificationServiceRequestUrl:attachUrl withAttachmentsComplete:^(NSArray *attachments, NSError *error) {
if (attachments.count > 0) {
self.bestAttemptContent.attachments = attachments; self.contentHandler(self.bestAttemptContent);
}else
{
self.contentHandler(self.bestAttemptContent);
}
}];
}
多媒體大小限制

自定義推送聲音
將聲音文件拖入到項(xiàng)目中,在MobPush后臺(tái)或者接口傳入對應(yīng)聲音文件名稱即可
-
API
+關(guān)注
關(guān)注
2文章
2380瀏覽量
66806 -
iOS
+關(guān)注
關(guān)注
8文章
3401瀏覽量
155513 -
SDK
+關(guān)注
關(guān)注
3文章
1101瀏覽量
51753
發(fā)布評論請先 登錄
iEST527車聯(lián)網(wǎng)OBD智能終端 SDK for iOS 說明
SDK、API、Open API有什么區(qū)別(iot開發(fā)平臺(tái))
OpenCV iOS應(yīng)該如何配置詳細(xì)方法說明
蘋果ios15正式版推送時(shí)間
MobPush丨Android端SDK API
SDK 與API 在視頻環(huán)境中的區(qū)別
MobPush Android SDK 廠商推送限制
MobPush iOS SDK iOS實(shí)時(shí)活動(dòng)
Mobpush與A/B測試:覆蓋多應(yīng)用場景下的精細(xì)化運(yùn)營神器
Mobpush上線跨時(shí)區(qū)推送功能,助力中國開發(fā)者應(yīng)用出海
Android推送問題排查技巧 針對MobPush安卓端推送問題的解決辦法
MobPush:Android SDK 集成指南
淘寶API SDK快速開發(fā)指南
MobPush iOS端SDK API推送配置方法
評論