插件集成访问MobPush插件、MobCommon插件点击购买并添加到项目当中。在uniapp的“manifest.json”中选择“app原生插件配置”,点击勾选上方添加的两个插件完成上述两步后请务必先打自定义基座哦,否则SDK代码无法生效!iOS平台相关配置添加Background Modes按照官网教程添加 Background Modes -> Remote notificationsAPP信息配置在manifest.json文件中配置如下属性属性描述示例MobAppKeymobAppkey2dxxxxxxxx0MobAppSecretmobAppSecreta7b9f1xxxxxxxxxxed158Android平台相关配置APP信息配置打开 manifest.xml配置如下属性属性描述示例Mob-AppKeymobAppkey2dbxxxxxxxc80Mob-AppSecretmobAppSecreta7b9fxxxxxxxxxxxxxxxxed158厂商信息配置添加自定义模块可从gitHub上下载对应厂商库并添加到自定义模块中进行使用,并配置厂商账号信息,点击查看自定义模块使用方法;示例:
配置AndroidManifest在HBuilderX中,对项目根目录右键菜单 "新建" -> "自定义文件"
输入文件名称 AndroidManifest.xml(注意大小写敏感),点击 “创建” 按钮新建文件
根据应用需求编辑添加需要的内容:<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mob.mobpush.plugin">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<permission android:name="${applicationId}.permission.MIPUSH_RECEIVE" />
<permission android:name="${applicationId}.push.permission.MESSAGE" />
<permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="${applicationId}.permission.MIPUSH_RECEIVE" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="${applicationId}.push.permission.MESSAGE" />
<uses-permission android:name="com.meizu.flyme.push.permission.RECEIVE" />
<uses-permission android:name="com.meizu.c2dm.permission.RECEIVE" />
<application>
<receiver
android:name="com.mob.pushsdk.plugins.huawei.PushHaiWeiRevicer"
android:exported="true">
<intent-filter>
<action android:name="com.huawei.android.push.intent.REGISTRATION" />
<action android:name="com.huawei.android.push.intent.RECEIVE" />
<action android:name="com.huawei.android.push.intent.CLICK" />
<action android:name="com.huawei.intent.action.PUSH_STATE" />
</intent-filter>
</receiver>
<service
android:name="com.mob.pushsdk.plugins.honor.HonorPushService"
android:exported="false">
<intent-filter>
<action android:name="com.hihonor.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.vivo.push.sdk.service.CommandClientService"
android:exported="true" />
<activity
android:name="com.vivo.push.sdk.LinkProxyClientActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<receiver
android:name="com.mob.pushsdk.plugins.vivo.PushVivoReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.vivo.pushclient.action.RECEIVE" />
</intent-filter>
</receiver>
<service
android:name="com.mob.pushsdk.plugins.oppo.OppoService"
android:exported="true"
android:permission="com.heytap.mcs.permission.SEND_PUSH_MESSAGE">
<intent-filter>
<action android:name="com.heytap.mcs.action.RECEIVE_MCS_MESSAGE" />
<action android:name="com.heytap.msp.push.RECEIVE_MCS_MESSAGE" />
</intent-filter>
</service>
<service
android:name="com.mob.pushsdk.plugins.oppo.CompatibleOppoService"
android:exported="true"
android:permission="com.coloros.mcs.permission.SEND_MCS_MESSAGE">
<intent-filter>
<action android:name="com.coloros.mcs.action.RECEIVE_MCS_MESSAGE" />
</intent-filter>
</service>
<receiver
android:name="com.mob.pushsdk.plugins.meizu.PushMeiZuRevicer"
android:exported="true">
<intent-filter>
<action android:name="com.meizu.flyme.push.intent.MESSAGE" />
<action android:name="com.meizu.flyme.push.intent.REGISTER.FEEDBACK" />
<action android:name="com.meizu.flyme.push.intent.UNREGISTER.FEEDBACK" />
<action android:name="com.meizu.c2dm.intent.REGISTRATION" />
<action android:name="com.meizu.c2dm.intent.RECEIVE" />
<category android:name="com.mob.mobpush.demo" />
</intent-filter>
</receiver>
<receiver
android:name="com.mob.pushsdk.plugins.huawei.PushHaiWeiRevicer"
android:exported="true">
<intent-filter>
<action android:name="com.huawei.android.push.intent.REGISTRATION" />
<action android:name="com.huawei.android.push.intent.RECEIVE" />
<action android:name="com.huawei.android.push.intent.CLICK" />
<action android:name="com.huawei.intent.action.PUSH_STATE" />
</intent-filter>
</receiver>
<receiver
android:name="com.mob.pushsdk.plugins.xiaomi.PushXiaoMiRevicer"
android:exported="true">
<intent-filter>
<action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" />
</intent-filter>
<intent-filter>
<action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" />
</intent-filter>
<intent-filter>
<action android:name="com.xiaomi.mipush.ERROR" />
</intent-filter>
</receiver>
</application>
</manifest>
接口调用引入模块(必要)const mobpush = uni.requireNativePlugin('mob-push')
功能接口提交用户隐私授权结果为保证您的App在集成MobSDK之后能够满足工信部相关合规要求,您应确保App安装首次冷启动且取得用户阅读您《隐私政策》授权之后,调用MobSDK.submitPolicyGrantResult回传隐私协议授权结果。反之,如果用户不同意您App《隐私政策》授权,则不能调用MobSDK.submitPolicyGrantResult回传隐私协议授权结果。 请参考链接合规指南/**
- 回传用户隐私授权结果
- @param isGranted用户是否同意隐私协议
*/
mobPushUniPlugin.submitPolicyGrantResult({"grant": true})
打开debug日志/**
设置打开debug日志
*/
mobPushUniPlugin.enableLog({"enableLog": true
})
设置推送环境(仅iOS)/**
- 设置推送环境
- @param isPro = true
*/
mobPushUniPlugin.setAPNsForProduction({'isPro': true})
配置推送配置(仅iOS)/**
- 设置推送配置 (必须调用)
- @param type = 7
- 无显示 0, 角标提醒 1, 声音提醒 2, 弹框提醒 4, 全部 7
*/
mobPushUniPlugin.setAPNsNotification({'type': 7})
/**
- 设置应用在前台有 Badge、Sound、Alert 三种类型,默认3个选项都有,iOS 10 以后设置有效
- @param type = 7
- 无显示 0, 角标提醒 1, 声音提醒 2, 弹框提醒 4, 全部 7
*/
mobPushUniPlugin.setAPNsShowForegroundType({'type': 7})
获取RegistrationID/**
* 获取RegistrationID
* @param {Function} callback = (result) => {"success":bool,"res":regID,"error":err}
*/
mobPushUniPlugin.getRegistrationID((result) => {
//todo something
})
添加消息事件监听/*
* 消息事件监听
*
* @param {Function} callback = (result) => {"success":bool,"res":String,"error":err}
*
* success:结果,true为操作成功
*
* res: 消息结构体 JSON字符串
* */
mobPushUniPlugin.addPushReceiver((result) => {})
清除事件监听(仅iOS)/**
- 清除事件监听
*/
mobPushUniPlugin.clearPushReceivers()
标签推送/*
* 新增标签,tags之间以;隔开
* */
mobPushUniPlugin.addTags({
"tags": "您的标签"
})
/*
* 删除所有标签
*
* */
mobPushUniPlugin.cleanAllTags()
/*
* 清除指定标签,tags之间以;隔开
* */
mobPushUniPlugin.deleteTags({
"tags": "您的标签"
})
/*
* 查询所有标签
* */
mobPushUniPlugin.getTags()
别名推送/*
* 查询所有别名
* */
mobPushUniPlugin.getAlias()
/*
* 新增别名
* @param alias = String
* */
mobPushUniPlugin.setAlias({
"alias": "您的别名"
})
/*
* 删除别名
* */
static deleteAlias() {
MobPushModule.deleteAlias();
}
推送状态/**
* 推送服务是否关闭
* @param {Function} callback = (result) => {"success":bool,"res":isStopeed,"error":err}
*/
mobPushUniPlugin.isPushStopped((result) => {
// todo something
})
/**
* 关闭推送服务
*/
mobPushUniPlugin.stopPush()
/**
* 开启推送服务
*/
mobPushUniPlugin.restartPush()
角标状态Android:/**
* 设置角标是否开启
*/
mobPushUniPlugin.setShowBadge({
"showBadge": true
})
/**
* 角标是否关闭
* @param {Function} callback = (result) => {"success":bool,"res":isStopeed,"error":err}
*/
mobPushUniPlugin.getShowBadge((result) => {
//todo something
})
iOS:/**
- 设置角标数量
- @param badge = 10
*/
mobPushUniPlugin.setBadge({'badge': 10})
/**
- 获取服务器角标数量
*/
mobPushUniPlugin.getBadge((result) => {
//todo something
})
/**
- 清空角标,但不清空通知栏消息
*/
mobPushUniPlugin.clearBadge()
注意事项合规指南:https://www.mob.com/wiki/detailed?wiki=216&id=78常见问题:https://www.mob.com/wiki/detailed?wiki=156&id=78
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。