我在我的反应原生项目[android平台]中使用了react-native-firebase来显示应用程序通知.使用此库,我可以在应用程序处于前台/后台/关闭状态时显示通知.
根据react本机firebase文档,当通知点击打开应用程序时,应触发onNotificationOpened.但是,在我的情况下不会发生这种情况,从不调用onNotificationOpened方法,并且getInitialNotification方法始终获取空值.
我也使用react-native-splash-screen库来显示启动画面.
这是来自App.js >> componentDidMount()的代码
firebase.messaging().requestPermission()
.then(() => {
const myAppChannel = new firebase.notifications.Android.Channel('my-channel',
'my Channel', firebase.notifications.Android.Importance.Max)
.setDescription('my channel');
firebase.notifications().android.createChannel(myAppChannel);
this.messageListener = firebase.messaging().onMessage((message) => {
const {title, body} = message.data;
const notificationDisplay = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle(title)
.setBody(body)
.setData({
key1: 'value1',
key2: 'value2',
}).setSubtitle('notification')
.setSound('default');
notificationDisplay
.android.setChannelId('my-channel')
.android.setSmallIcon('ic_launcher')
.android.setAutoCancel(true).android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications().displayNotification(notificationDisplay);
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
//never gets called
console.log('onNotificationOpened was triggered on notification …Run Code Online (Sandbox Code Playgroud) 我正在使用 jQuery ajax 向某些 API 发送请求。由于 CORS 政策,我在浏览器控制台上收到 CORS 错误
这是通过代码
$.ajax({
url: sendHere,//api url
type: 'GET',
contentType: 'text/plain',
crossDomain: true,
beforeSend: function(xhr){
xhr.withCredentials = true;
},
}).done(function (result) {
console.log(result);
}).error(function (err) {
//console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
错误
请求的资源上存在“Access-Control-Allow-Origin”标头。因此,不允许访问来源“ http://www.mywebsite.com ”。
我尝试通过安装 chrome 扩展以启用允许跨源请求来解决此问题。这个扩展以某种方式解决了我的问题并得到了 api 的响应。但安装扩展并不好。
我还尝试使用 JSONP(dataType:'jsonp') 发出请求,但 api 给出的响应不是 json 格式,它是字符串,因此会出现错误。
使用 JSONP 编写代码
$.ajax({
url: sendHere,//api url
type: 'GET',
crossDomain: true,
dataType:'jsonp',
}).done(function (result) {
console.log(result);
}).error(function (err) {
//console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
未捕获的引用错误:未定义 E0002,其中“E0002”是来自 api 的响应字符串
!!!请帮忙!!!
即使资源/视图目录中的视图可用,laravel 也会向我显示此错误
未找到视图 [名称]。
一切正常,直到当前发生令牌不匹配错误我无法访问视图目录中的任何视图。
Route::get('/', function () {
return view('welcome');
});//in web.php
Run Code Online (Sandbox Code Playgroud)
正在抛出View [welcome] not found。例外
注意 我在 homestead 运行我的应用程序 vagrant
ajax ×1
api ×1
homestead ×1
javascript ×1
jquery ×1
json ×1
laravel-5.4 ×1
php ×1
react-native ×1
vagrant ×1