バックグラウンドモードまたはシャットダウンモードでアプリが通知を受け取るのに問題があります。私は自分のアプリでfirebaseメッセージングを実装する方法についてFirebaseのガイドに従ってきました。以前はGCM(Googleクラウドメッセージング)を使用していましたが、すべて正常に動作しましたが、Firebaseにアップグレードしてから動作させることはできません。アプリを起動するとすぐに、バックグラウンドやシャットダウン時に送信した通知(Firebaseコンソール通知)がすべて配信されます。Firebaseメッセージング。バックグラウンドモードまたはシャットダウン時にiOSアプリが通知を受信しない
私が持っている:Firebaseコンソール上
- 作成したプロジェクト
- はAPNS開発証明書
- がに証明書をアップロード作成した
- 正しいバンドルIDでfirebaseプロジェクトに私のアプリを追加しましたFirebaseコンソールの私のアプリ
wo私のInfo.plistファイルでFirebaseAppDelegateProxyEnabledをNOに設定して、スウィズルを無効にしていることに言及しています。
関連するコード:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let types: UIUserNotificationType = [UIUserNotificationType.Badge, UIUserNotificationType.Alert, UIUserNotificationType.Sound]
let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
FIRApp.configure()
}
func connectToFcm() {
FIRMessaging.messaging().connectWithCompletion { (error) in
if (error != nil) {
print("Unable to connect with FCM")
} else {
print("Connected to FCM.")
self.refreshToken()
}
}
}
func refreshToken(){
if let refreshedToken = FIRInstanceID.instanceID().token() {
gcmToken = refreshedToken
userDefaults.setValue(gcmToken, forKey: CONSTANTS.GCM_TOKEN)
if(userDefaults.boolForKey("UserLoggedIn")){
pushGcmToken() //push the token to server
}
}
}
func onTokenRefresh() {
refreshToken()
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
NSLog("didReceiveRemoteNotification \(userInfo)")
FIRMessaging.messaging().appDidReceiveMessage(userInfo)
handleRemoteNotification(userInfo)
}
func handleRemoteNotification(userInfo: [NSObject : AnyObject]){
if let notification = userInfo["notification"] as? [NSObject : AnyObject]{
let bodyNot = notification["body"] as! String
var titleNot = "Ändring"
var category = "UNIFIED_OTHER_CATEGORY"
if(notification["title"] != nil){
titleNot = (notification["title"] as! String == "Call" ? "Inkomande samtal" : notification["title"]) as! String
category = "UNIFIED_CALL_CATEGORY"
}
let notis = UILocalNotification()
notis.alertTitle = titleNot
notis.alertBody = bodyNot
notis.soundName = UILocalNotificationDefaultSoundName // play default sound
notis.userInfo = ["UUID": "122" ] // assign a unique identifier to the notification so that we can retrieve it later
notis.category = category
notis.fireDate = NSDate()
UIApplication.sharedApplication().scheduleLocalNotification(notis)
}
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
NSLog("didRegisterForRemoteNotificationsWithDeviceToken \(deviceToken)")
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
}
私も上のスウィズルで試してみました。同じことが起こっている。私は、正しい方向への助けやヒントを非常に感謝します。 Info.plistのセットでは
こんにちは、あなたは答えを見つけましたか? –
firebaseの 'content-available = 1'に相当するファイルはありますか? – wyu