关于前端:APP怎么免费接入MobPush

7次阅读

共计 2614 个字符,预计需要花费 7 分钟才能阅读完成。

1、获取 AppKey

申请 Appkey 的流程,请点击
http://bbs.mob.com/thread-821…

2、下载 SDK

下载解压后,如下图:

目录构造
(1)Sample:演示 Demo。

(2)SDK:集成我的项目时,只需导入此文件夹即可。具体阐明在外面的 2 个文件夹:

Required:必要的依赖库(必要)。

MobPush:MobPush 的 SDK。

3、导入 SDK

(1)手动下载 SDK 导入
解压下载的 ZIP 包,将解压后的 SDK 增加到我的项目中。
留神:该步骤中增加时,请抉择“Create groups for any added folders”单选按钮组。如果你抉择“Create folder references for any added folders”,一个蓝色的文件夹援用将被增加到我的项目并且将无奈找到它的资源。
(2)pod 导入
1、首先 cd 至我的项目的根目录,执行 pod setup;
2、按需在 Podfile 文件中增加命令:
pod ‘mob_pushsdk’
3、如果之前没有装置过,第一次应用请先执行
装置库:pod install
,如果之前曾经装置过,那只须要在执行
更新库:pod update

4、增加我的项目依赖库

必须增加的依赖库如下(Xcode 7 之后 .dylib 库后缀名更改为.tbd):
libstdc++.dylib
libz.1.2.5.dylib
CoreLocation.framework

5、MobPush 的初始化配置和性能接口。

5.1 配置 AppKey 和 AppSecret
在我的项目的 Info.plist 中增加 2 个字段:MOBAppKey 和 MOBAppSecret,对应的值是在 mob.com 官网申请的利用的 AppKey 和 AppSecret。

在 Info.plist 配置 Privacy – Location When In Use Usage Description 权限以及 App Transport Security Settings。

证书里须要开明 apns 性能,而后在我的项目里设置,如下:

5.2 推送配置(以下代码具备通用性,可间接粘贴应用)在 - (BOOL)application:(UIApplication)application didFinishLaunchingWithOptions:(NSDictionary)launchOptions 中进行推送配置即可。引入头文件:import <MobPush/MobPush.h> 调用办法:// 设置推送环境 #ifdef DEBUG [MobPush setAPNsForProduction:NO];#else [MobPush setAPNsForProduction:YES];#endif //MobPush 推送设置(取得角标、声音、弹框揭示权限)MPushNotificationConfiguration *configuration = [[MPushNotificationConfiguration alloc] init];
configuration.types = MPushAuthorizationOptionsBadge | MPushAuthorizationOptionsSound | MPushAuthorizationOptionsAlert;
[MobPush setupNotification:configuration];5.3 性能接口调用所有的性能接口都在 MobPush.h 中。目前的 MobPush 的推送机制是,如果利用不处于 active 状态,会以苹果的推送零碎(APNs)模式发送到手机上。(目前推送都是走 APNs,监听不到回调,自定义音讯除外)如果利用是处于 active 状态,推送会以利用内推送下发到利用中,这时只须要应用一个告诉监听 @“MobPushDidReceiveMessageNotification”告诉即可。例子如下:先引入头文件:#import <MobPush/MobPush.h> 再调用办法:[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMessage:) name:MobPushDidReceiveMessageNotification object:nil]; 收到的音讯数据可能是:1、UDP 推送,2、UDP 自定义音讯,3、APNs,4、本地告诉。依据不同的类型做相应显示即可,具体例子如下:// 收到告诉回调 - (void)didReceiveMessage:(NSNotification *)notification
{

MPushMessage *message = notification.object;

switch (message.messageType)
{
    case MPushMessageTypeNotification:
    {// UDP 告诉}
        break;
    case MPushMessageTypeCustom:
    {// 自定义音讯}
        break;
    case MPushMessageTypeAPNs:
    {// APNs 回调            NSLog(@"%@", message.apnsDict);
        
        if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
        {// 前台}
        else            {// 后盾}
    }
        break;
    case MPushMessageTypeLocal:
    { // 本地告诉回调            NSString *body = message.notification.body;
        NSString *title = message.notification.title;
        NSString *subtitle = message.notification.subTitle;
        NSInteger badge = message.notification.badge;
        NSString *sound = message.notification.sound;

        NSLog(@"收到本地告诉:{\nbody:%@,\ntitle:%@,\nsubtitle:%@,\nbadge:%ld,\nsound:%@,\n}",body, title, subtitle, badge, sound);
    }
        break;
    default:
        break;
}

}

原文链接:

正文完
 0