反应本机firebase IOS推送通知
我正在尝试使用FB进行推送通知。在android bud IOS上一切正常都有一些问题。 主要问题是我无法收到通知。->Bud有时会收到正确的通知,一切正常。当我重新安装应用程序时,Bud不会在iPhone上收到通知。它是随机工作的 我用 我的吊舱文件反应本机firebase IOS推送通知,firebase,react-native,react-native-ios,react-native-firebase,Firebase,React Native,React Native Ios,React Native Firebase,我正在尝试使用FB进行推送通知。在android bud IOS上一切正常都有一些问题。 主要问题是我无法收到通知。->Bud有时会收到正确的通知,一切正常。当我重新安装应用程序时,Bud不会在iPhone上收到通知。它是随机工作的 我用 我的吊舱文件 pod 'Firebase/Core', '~> 6.3.0' pod 'Firebase/Messaging', '~> 6.3.0' AppDelegate.m #import <Firebase.h> #i
pod 'Firebase/Core', '~> 6.3.0'
pod 'Firebase/Messaging', '~> 6.3.0'
AppDelegate.m
#import <Firebase.h>
#import <UserNotifications/UserNotifications.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"
...
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
[RNFirebaseNotifications configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
UIUserNotificationSettings *settings =
[UIUserNotificationSettings
settingsForTypes: (UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
// Register the supported interaction types.
UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
下面是我如何在代码中使用它:
import firebase from 'react-native-firebase';
const getToken = () => {
firebase.messaging().getToken().then((token) => {
console.log('XXXXX getToken: ', token);
firebase.messaging().ios.registerForRemoteNotifications();
});
};
const requestPermission = () => {
try {
firebase.messaging().requestPermission().then((xx) => {
console.log('XXXX requestPermission', xx);
});
} catch (error) {
console.log('XXXX requestPermission User has rejected permissions');
}
};
export const checkPermission = () => {
// firebase.messaging().ios.registerForRemoteNotifications();
firebase.messaging().hasPermission().then((permission) => {
console.log('XXXXX hasPermission check: ', permission);
if (permission) {
console.log('XXXX hasPermission TRUE');
getToken();
} else {
console.log('XXXX hasPermission FALSE');
requestPermission();
}
}).catch((e) => {
console.log('XXXXX hasPermission ERROR: ', e);
});
};
export const listeners = () => {
console.log("XXXXX Listeners setup OK!!");
firebase.notifications().onNotificationDisplayed((notification) => {
console.log("XXXXX onNotificationDisplayed", notification);
});
firebase.notifications().onNotification((notification) => {
console.log("XXXXX LISTENER onNotification", notification);
});
firebase.notifications().onNotificationOpened((notificationOpen) => {
console.log("XXXXX LISTENER onNotificationOpened");
});
firebase.notifications().getInitialNotification().then((notificationOpen)=> {
console.log("XXXXX LISTENER getInitialNotification OK", notificationOpen);
}).catch((error)=> {
console.log("XXXXX LISTENER getInitialNotification ERROR");
});
firebase.messaging().onMessage((message) => {
console.log("XXXXX LISTENER onMessage");
});
}
我正在将此文件导入主组件
componentDidMount() {
checkPermission();
listeners();
}
在安卓系统上一切正常,我能够接收通知并提取所有数据。
但对于ios,我已经准备好了所有设置,它应该可以通过日志工作:
一切看起来都很好。。。
现在我尝试向手机发送通知,但什么也没发生。但是,如果我尝试直接将其发送到该令牌,它将正常工作,我将收到通知
有时它开始工作,我会收到通知,当我重新安装应用程序,它不再工作
有解决办法吗 我的解决方案:
更新Cocopod。所有问题都消失了
pod 'Firebase/Core', '~> 6.5.0'
pod 'Firebase/Messaging', '~> 6.5.0'
componentDidMount() {
checkPermission();
listeners();
}
pod 'Firebase/Core', '~> 6.5.0'
pod 'Firebase/Messaging', '~> 6.5.0'