使用firebase API打开特定页面 [英] open specific page using firebase api
问题描述
var nTitle =来自+ $ rootScope的新消息。 clients_firstName;
var to =DeviceToken在这里;
var notification = {
'title':nTitle,
//'body':'点击这里查看更多详情...',
'icon':'firebase- logo.png',
'click_action':'openapp'
};
var key ='您的钥匙';
fetch('https://fcm.googleapis.com/fcm/send',{$ b $'method':'POST',
'headers':{
'Authorization ':'key ='+ key,
'Content-Type':'application / json'
},
'body':JSON.stringify({
'notification' :data,
'to':to
})
})。then(function(response){
//console.log(\"res,response); $ catch(function(error){
console.error(err,error);
});
推送通知会在设备上成功发送。
但是当我点击通知时,具体页面应该是打开的。
例如 然后,当我点击按钮时,'somepage'应该是打开的。 AndroidManifest.xml 我的项目结构 如果我点击通知,我想打开产品或关于页面然后我要做什么? 这里有什么错?请告诉我适当的解决方案。'click_action':'openapp / somepage'$ c
$ b
< activity android:name =MainActivityandroid: android:windowModel =android:style / Theme.DeviceDefault.NoActionBarandroid:windowMyAdmin =android: adjustResize >
< intent-filter>
< category android:name =android.intent.category.BROWSABLE/>
< / intent-filter>
< / activity>
- 平台
- 插件
--www
--app
- 关于
- 关于.bout.html
--about.ctrl.js
--product
--product.html
--product.ctrl.js
--css
--js
--lib
index.html
我知道你问关于离子1.但是我只知道离子2.希望这将帮助你。
我认为你应该在你的通知的附加数据部分添加关于你需要打开的页面的信息。就像这样:
$ $ p $ 'body':JSON.stringify({
'notification':data,
'to':to,
'data':{
'action':'需要的页面'
}
})
然后你就可以在订阅方法上看到它。就像这样:
$ $ p $ $ $ $ c $ fcm.onNotification()。subscribe(data => {
console.log( ('data',data);
if(data ['action']&& data ['action'] =='Needed page'){
this.navCtrl.push('Needed page' ); //使用导航控制器打开需要的页面
}
})
对于原生的cordova FCM插件:
FCMPlugin.onNotification(function(data){
console.log(data ('data');
if(data ['action']&& data ['action'] =='Needed page'){
this.navCtrl.push('Needed page') ; //使用导航控制器打开需要的页面
}
});
I am sending push notification to devices using below code.
var nTitle = "New message from " + $rootScope.clients_firstName;
var to = "DeviceToken is here";
var notification = {
'title': nTitle,
//'body': 'Click here to more details...',
'icon': 'firebase-logo.png',
'click_action': 'openapp'
};
var key = 'your key';
fetch('https://fcm.googleapis.com/fcm/send', {
'method': 'POST',
'headers': {
'Authorization': 'key=' + key,
'Content-Type': 'application/json'
},
'body': JSON.stringify({
'notification': data,
'to': to
})
}).then(function(response) {
//console.log("res ", response);
}).catch(function(error) {
console.error("err ", error);
});
push notification sends on device successfully.
But when I click on notification the specific page should be open.
For example 'click_action' : 'openapp/somepage'
Then the 'somepage' should be open when I click on pushnotification.
AndroidManifest.xml
<activity android:name="MainActivity" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="openapp" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
My project structure
--platforms
--plugins
--www
--app
--about
--about.html
--about.ctrl.js
--product
--product.html
--product.ctrl.js
--css
--js
--lib
index.html
If I click on notification and I want to open product or about page then what I have to do?
What is wrong here? Please tell me the proper solution.
I know that you ask about Ionic 1. But I only know for Ionic 2. Hope this will help you.
I think you should add information about what page you need to open in additional data section of your notice. Something like this:
'body': JSON.stringify({
'notification': data,
'to': to,
'data' : {
'action' : 'Needed page'
}
})
And then you should catch it on the subscribe method. Something like that:
fcm.onNotification().subscribe(data=>{
console.log("data", data);
if (data['action'] && data['action'] == 'Needed page'){
this.navCtrl.push('Needed page'); //Use Navigation controller to open needed page
}
})
For native cordova FCM plugin:
FCMPlugin.onNotification(function(data){
console.log("data", data);
if (data['action'] && data['action'] == 'Needed page'){
this.navCtrl.push('Needed page'); //Use Navigation controller to open needed page
}
});
这篇关于使用firebase API打开特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!