|
需求:点击通知,打开APP,并通过后台api所传参数,跳转到对应页面
问题:点击通知,无法打开APP,下面两种接收方式也都无法接收
使用的推送模块是:tpnsPushPlus
PHP后端api代码:
require_once("tpns.php");
$android = new tpns\AndroidMessage;
$android->n_ch_id = "chid";
$action=new tpns\AndroidAction;
$action->action_type = 3;
$action->intent = "myapp://index?id=12345";
$android->action = $action;
$req = tpns\NewRequest(
tpns\WithAudienceType(tpns\AUDIENCE_TOKEN_LIST),
tpns\WithMessageType(tpns\MESSAGE_NOTIFY),
tpns\WithTitle("标题"),
tpns\WithContent("xxx消息"),
tpns\WithAndroidMessage($android),
// tpns\WithIOSMessage($ios),
tpns\WithTokenList(array("02f958c01842b4a34c9badb0f429703285f0")),
tpns\WithEnvironment(tpns\ENVIRONMENT_PROD)
);
APP config.xml配置
<intent-filter>
<action name="android.intent.action.VIEW"/>
<category name="android.intent.category.DEFAULT"/>
<data scheme="myapp" host="" path="/index"/>
</intent-filter>
APP接收代码:
第一种
document.addEventListener('appReadystart', function(e) {
api.addEventListener({
name: 'appLaunch',
extra: {
type: 'url'
},
callback: function(ret, err) {
var url = ret.url;
console.log(url)
if (url.startsWith('myapp://index?id=')) {
var id = url.split('=')[1];
// 根据id加载并展示详情内容
// displayDetails(id);
}
}
});
});
第二种
api.addEventListener({
name: 'appintent'
}, function (ret, err) {
console.log("addEventListener-appintent" + JSON.stringify(ret));
var appParam = ret.appParam;
});
|
|