集成筹备
注册账号
应用MobSDK之前,须要先在MobTech官网注册开发者账号,并获取MobTech提供的AppKey和AppSecret,详情能够点击查看注册流程
下载.unitypackage包
关上 Github 下载 MobPush-For-Unity 我的项目,下载实现后间接双击或者在Unity外面抉择关上 MobPush.unitypackage,导入相干资源和脚本到您的 Unity我的项目即可应用。
导入unitypackage
全副抉择即可(其中Demo.cs 为API应用和页面示例,可删除)
批改unity 编译环境
Android 集成编译配置
资源批改
删掉Android目录下的 baseProjectTemplate.gradle 、launcherTemplate.gradle文件
批改unity配置
应用零碎的gradle配置文件
减少MobPush的gradle配置
批改baseProjectTemplate.gradle和launcherTemplate.gradle
(注:此处批改为新生成的baseProjectTemplate.gradle文件和launcherTemplate.gradle文件)
baseProjectTemplate.gradle
1.在classpath ‘com.android.tools.build:gradle’后增加mob的classpathclasspath "com.mob.sdk:MobSDK:+"
2.增加MobPush须要的maven地址
maven { url "https://mvn.mob.com/android/"}
3.参考示例如截图
launcherTemplate.gradle
1.批改launcherTemplate.gradle减少MobPush配置
apply plugin: 'com.mob.sdk'
MobSDK {
appKey "xxxxxxxxx"
appSecret "xxxxxxxxxx"
MobPush {
debugLevel 4
devInfo {
HUAWEI{
appId "xxxxxxxxx"
}
XIAOMI {
appId "xxxxxxx"
appKey "5581830029242"
}
MEIZU {
appId "xxxxx"
appKey "3fc6d1acc7ea4f90a0304967ee3a74ae"
}
OPPO {
appKey "xxxxxxxx"
appSecret "c850609d8a0f492f8b9eeca1189aaec2"
}
VIVO {
appId "xxxxxx"
appKey "9b01729c-6140-4ad3-ac79-4c4543e12130"
}
}
}
}
2.参考示例截图
在gradle.properties中增加代码
`MobSDK.spEdition=FP
`
挂载MobPush如图
配置签名文件和包名
1.配置本人我的项目的签名文件
2.配置本人我的项目的包名
设置隐衷受权回调
为保障您的App在集成MobSDK之后可能满足工信部相干合规要求,您应确保App装置首次冷启动且获得用户浏览您《隐衷政策》受权之后,调用Mob提交到的隐衷协定回传函数uploadPrivacyPermissionStatus回传隐衷协定受权后果。 反之,如果用户不批准您App《隐衷政策》受权,则不能调用uploadPrivacyPermissionStatus回传隐衷协定受权后果。 详情参考:合规指南
//隐衷受权接口调用,此接口务必不能漏调用,否则导致SDK不失效
mobPush.updatePrivacyPermissionStatus(true);
推送接口
初始化和绑定监听(gameObject.GetComponent)
void Start ()
{
mobPush = gameObject.GetComponent();//初始化MobPush
mobPush.onNotifyCallback = OnNitifyHandler;//音讯回调监听
mobPush.onTagsCallback = OnTagsHandler;//标签解决回调监听
mobPush.onAliasCallback = OnAliasHandler;//别名解决回调监听
mobPush.onDemoReqCallback = OnDemoReqHandler;
//demo申请接口回调(为了不便测试,提供在客户端发送告诉的接口,仅供测试时应用)
mobPush.onRegIdCallback = OnRegIdHandler;//获取注册ID异步监听回调接口
}
void OnNitifyHandler (int action, Hashtable resulte)
{
Debug.Log ("OnNitifyHandler");
if (action == ResponseState.CoutomMessage)
{
Debug.Log ("CoutomMessage:" + MiniJSON.jsonEncode(resulte));
}
else if (action == ResponseState.MessageRecvice)
{
Debug.Log ("MessageRecvice:" + MiniJSON.jsonEncode(resulte));
}
else if (action == ResponseState.MessageOpened)
{
Debug.Log ("MessageOpened:" + MiniJSON.jsonEncode(resulte));
}
}
void OnTagsHandler (int action, string[] tags, int operation, int errorCode)
{
Debug.Log ("OnTagsHandler action:" + action + " tags:" + String.Join (",", tags) + " operation:" + operation + "errorCode:" + errorCode);
}
void OnAliasHandler (int action, string alias, int operation, int errorCode)
{
Debug.Log ("OnAliasHandler action:" + action + " alias:" + alias + " operation:" + operation + "errorCode:" + errorCode);
}
void OnRegIdHandler (string regId)
{
Debug.Log ("OnRegIdHandler-regId:" + regId);
}
void OnDemoReqHandler (bool isSuccess)
{
Debug.Log ("OnDemoReqHandler:" + isSuccess);
}
发送本地告诉(LocalNotifyStyle )
LocalNotifyStyle style = new LocalNotifyStyle ();
style.setContent ("Text");
style.setTitle ("title");
#if UNITY_ANDROID
Hashtable extras = new Hashtable ();
extras["key1"] = "value1";
extras["key2"] = "value1";
style.setExtras (extras);
#endif
mobPush.setMobPushLocalNotification (style);
自定义告诉栏款式( CustomNotifyStyle)
CustomNotifyStyle style = new CustomNotifyStyle ();
#if UNITY_IPHONE
style.setType(CustomNotifyStyle.AuthorizationType.Badge | CustomNotifyStyle.AuthorizationType.Sound | CustomNotifyStyle.AuthorizationType.Alert);
#elif UNITY_ANDROID
style.setContent ("Content");
style.setTitle ("Title");
style.setTickerText ("TickerText");
#endif
mobPush.setCustomNotification(style);
获取注册ID (getRegistrationId)
mobPush.getRegistrationId();
增加标签 (addTags)
String[] tags = { "tags1", "tags2", "tags3" };
mobPush.addTags(tags);
获取标签 (getTags)
mobPush.getTags();
删除标签 (deleteTags)
String[] tags = { "tags1", "tags2", "tags3" };
mobPush.deleteTags(tags);
革除全副标签 (cleanAllTags )
mobPush.cleanAllTags();
增加别名 (addAlias)
mobPush.addAlias("alias");
获取别名 (getAlias)
mobPush.getAlias();
革除别名 (cleanAllAlias)
mobPush.cleanAllAlias();
进行告诉服务 (stopPush)
mobPush.stopPush();
重启告诉服务 (restartPush)
mobPush.restartPush();
判断告诉是否被进行,返回值:bool类型(isPushStopped)
mobPush.isPushStopped();
点击告诉后是否关上利用首页(setClickNotificationToLaunchPage)
mobPush.setClickNotificationToLaunchPage(false);
增加混同配置
为了避免二次混同MobPush,须要在我的项目混同文件中增加:
-keep class com.mob.**{*;}
-dontwarn com.mob.**
如果同时集成了华为、小米、魅族等渠道推送,同时也须要在我的项目中增加防二次混同配置:
-keep class com.huawei.**{*;}
-keep class com.meizu.**{*;}
-keep class com.xiaomi.**{*;}
-keep class android.os.SystemProperties