关于ios:MobPush-iOS-SDK-API

概述

MobPush 注册推送,获取推送id等办法均可在SDK的”MobPush.h”中进行查看,也能够下载MobPush的Demo进行参考。

推送环境设置(setAPNsForProduction)

/**
 @param isProduction 是否生产环境。 如果为开发状态,设置为 NO; 如果为生产状态,应改为 YES。 Default 为 YES 生产状态
 */
+ (void)setAPNsForProduction:(BOOL)isProduction;

示例代码

// 设置推送环境
#ifdef DEBUG

    [MobPush setAPNsForProduction:NO];

#else

    [MobPush setAPNsForProduction:YES];

#endif

注册推送配置(setupNotification)

/**
@param configuration 配置信息
 */
+ (void)setupNotification:(MPushNotificationConfiguration *)configuration;

示例代码

//MobPush推送设置(取得角标、声音、弹框揭示权限),利用要收到推送(角标、声音、弹框揭示)须要先申请权限,这个办法就是设置推送配置、申请权限的办法。用法可参考以下的例子。

MPushNotificationConfiguration *configuration = [[MPushNotificationConfiguration alloc] init];

configuration.types = MPushAuthorizationOptionsBadge | MPushAuthorizationOptionsSound | MPushAuthorizationOptionsAlert;

[MobPush setupNotification:configuration];

告诉回调接口(MobPushDidReceiveMessageNotification)

/**
 收到音讯告诉(数据是MPushMessage对象,可能是推送数据、自定义音讯数据,APNs、本地告诉等的回调)
 */
extern NSString *const MobPushDidReceiveMessageNotification;   

阐明:利用收到音讯,MobPush会发动一个告诉,开发者只须要建设一个告诉收听 MobPushDidReceiveMessageNotification 并作相应解决即可。收到的数据是一个MPushMessage对象,可能是推送数据,也可能是自定义音讯数据。如果是推送数据,开发者能够通过MobPush.h中的addLocalNotification:办法,让音讯以本地告诉模式显示(iOS 10之前的零碎利用内是不会显示告诉的)。

示例代码

// 注册告诉回调
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMessage:) name:MobPushDidReceiveMessageNotification object:nil];

//查看告诉参数能够打印notification
- (void)didReceiveMessage:(NSNotification *)notification{}

获取推送RegistrationID (getRegistrationID)

获取推送RegistrationID接口,RegistrationID可与用户id绑定,实现向指定用户推送音讯,此接口必须在推送设置接口之后调用。

/**
 获取注册id(可与用户id绑定,实现向指定用户推送音讯)

 @param handler 后果
 */
+ (void)getRegistrationID:(void(^)(NSString *registrationID, NSError *error))handler;

示例代码

[MobPush getRegistrationID:^(NSString *registrationID, NSError *error) {

 NSLog(@"registrationID = %@--error = %@", registrationID, error);

}];

推送标签API(addTags)

MobPush反对依据标签进行推送,所以也提供了对标签的相应操作。

/**
 获取所有标签
 @param handler 后果
 */
+ (void)getTagsWithResult:(void (^) (NSArray *tags, NSError *error))handler;/**

/**
 增加标签
 @param tags 标签组
 @param handler 后果
 */
+ (void)addTags:(NSArray<NSString *> *)tags result:(void (^) (NSError *error))handler;

/**
 删除标签
 @param tags 须要删除的标签
 @param handler 后果
 */
+ (void)deleteTags:(NSArray<NSString *> *)tags result:(void (^) (NSError *error))handler;

/**
 清空所有标签
 @param handler 后果
 */
+ (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同样反对依据别名推送,所以也提供了对别名的相应操作。

/**
 获取别名
 @param handler 后果
 */
+ (void)getAliasWithResult:(void (^) (NSString *alias, NSError *error))handler;

/**
 设置别名
 @param alias 别名
 @param handler 后果
 */
+ (void)setAlias:(NSString *)alias result:(void (^) (NSError *error))handler;

/**
 删除别名
 @param handler 后果
 */
+ (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 音讯申请(音讯标识、音讯具体信息、触发形式)
 @param handler 后果,iOS10以上胜利result为UNNotificationRequest对象、iOS10以下胜利result为UILocalNotification对象,失败result为nil
*/
+ (void)addLocalNotification:(MPushNotificationRequest *)request result:(void (^) (id result, NSError *error))handler;

示例代码

#import <MobPush/MobPush.h>
[MobPush addLocalNotification:request result:^(id result, NSError *error) {};

设置角标(setBadge)

/**
 设置角标值到Mob服务器
 本地先调用setApplicationIconBadgeNumber函数来显示角标,再将该角标值同步到Mob服务器,
 @param badge 新的角标值(会笼罩服务器上保留的值)
 */
+ (void)setBadge:(NSInteger)badge;

/**
 革除角标,但不清空告诉栏音讯
 */
+ (void)clearBadge;

示例代码

[MobPush setBadge:8];

[MobPush clearBadge];

关上和敞开近程推送(stopPush)

/**
 敞开近程推送(利用内推送和本地告诉不受影响,只敞开近程推送)
 */
+ (void)stopPush;

/**
 关上近程推送
 */
+ (void)restartPush;

示例代码

[MobPush stopPush];

[MobPush restartPush];

利用处于前台时设置推送音讯的提醒类型(setAPNsShowForegroundType)

/**
 设置利用在前台有 Badge、Sound、Alert 三种类型,默认3个选项都有,iOS 10 当前设置无效。
 如果不想前台有 Badge、Sound、Alert,设置 MPushAuthorizationOptionsNone
 @param type 类型
 */
+ (void)setAPNsShowForegroundType:(MPushAuthorizationOptions)type;

示例代码

//设置后,利用在前台时不展现告诉横幅、角标、声音。(iOS 10 当前无效,iOS 10 以前原本就不展现)
[MobPush setAPNsShowForegroundType:MPushAuthorizationOptionsNone];

指定删除收到的本地推送(removeNotificationWithIdentifiers)

/**
 删除指定的推送告诉(能够删除未发送或者曾经发送的本地告诉)
 @param identifiers 推送申请标识数组,为nil,删除所有告诉
 */
+ (void)removeNotificationWithIdentifiers:(NSArray <NSString *> *)identifiers;

示例代码

[MobPush removeNotificationWithIdentifiers:nil];

推送关上指定利用内指定页面(initWithMobPushScene)

后盾配置

如果开发者想要对告诉音讯进行点击跳转到app内指定页面的操作,能够在开发者治理后盾关上配置开关和参数设置。

Scheme地址:为开发者自定义的控制器门路。

传递参数:为跳转控制器的初始化参数。

代码配置

开发者须要在本人的利用内对所跳转的控制器进行相干代码设置。如下:(可参照demo中PushViewController.m) 参考链接(可参考示例代码也能够参考链接去设置): https://www.jianshu.com/p/9abb125b5456

/**
 设置控制器门路
 @return 控制器门路
 */
+ (NSString *)MobPushPath;

/**
 初始化场景参数

 @param params 场景参数
 @return 控制器对象
 */
- (instancetype)initWithMobPushScene:(NSDictionary*)params;

示例代码

#import <MobPush/UIViewController+MobPush.h>

// 还原标识ios能够自定义在对应vc中实现如下还原代码
+ (NSString *)MobPushPath
{
    return @"mlink://com.mob.mobpush.link";
}

//点击推送场景还原页面参数
- (instancetype)initWithMobPushScene:(NSDictionary *)params
{
    if (self = [super init])
    {

    }
    return self;
}

富媒体推送应用(MobPushServiceExtension)

增加 MobPushServiceExtension 依赖库

设置 Notification Service 最低运行版本为 10.0:

开启富媒体地址Http拜访反对

应用 MobPushServiceExtension 进行富媒体推送

在 NotificationService.m 文件中,导入 MobPushServiceExtension 的头文件:

#import <MobPushServiceExtension/MobPushServiceExtension.h>

进入MobPush开发者后盾通过url(带有后缀格局的文件地址)或者文件的形式发送富媒体告诉。(必须勾选mutable-content选项)

调用handelNotificationServiceRequestUrl办法。接管到 APNs 告诉后,SDK 判断是否有富媒体资源request.content.userInfo[@“attachment”],如果富媒体资源存在则SDK下载资源,下载实现后以 Block 形式回调返回 attachments 资源数组对象和error错误信息。

示例代码

- (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);

        }

    }];
}

多媒体大小限度

自定义推送声音

将声音文件拖入到我的项目中,在MobPush后盾或者接口传入对应声音文件名称即可

iOS送达统计

开发者可应用MobPushServiceExtension SDK上报APNs信息的达到状态。

集成办法:

  1. 1.将*_MobPushServiceExtension *_SDK引入到您创立好的Service Extension工程中
  2. 2.在办法 didReceiveNotificationRequest:withContentHandler:办法中调用deliverNotificationRequest:MobAppSecret:with:办法,以上报接管到的APNs音讯,在该办法的block回调中进行APNs音讯的显示
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler
{
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];

    __weak typeof(self) weakSelf = self;
    [MobPushServiceExtension deliverNotificationRequest:request MobAppSecret:@"appSecret" with:^{
        weakSelf.contentHandler(weakSelf.bestAttemptContent);
    }];
}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理