0

私のfirebase iosアプリに問題があります。私のアプリケーションは通知を受けておらず、さらにdidReceiveRemoteNotificationが呼び出されていません。私は最近、アプリのために2つのターゲットを作った。別のターゲットを作成する前に、通知はうまくいきました。明確にするFCM didReceiveRemoteNotificationが呼び出されていません

もの:

  1. 私は各ターゲットのGoogle-Info.plistInfo.plistファイルを分離しています。これは、私が2つの異なるデータベースにアクセスし、どちらかの明示的な操作を実行することができるように検証されます。

  2. 私はターゲットごとに別々のプロビジョニングプロファイルを持っており、APNS開発証明書とプロダクション証明書もあります。

  3. すべてのターゲットには、APN認証キーが割り当てられます。すべてこれにより

は、私は、次のコードを実行しています行なわ:行われたすべての本で

AppDelegate.swift

import UIKit 
import CoreData 
import Firebase 
import UserNotifications 
import FirebaseInstanceID 
import FirebaseMessaging 
import IQKeyboardManagerSwift 
import Fabric 
import Crashlytics 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate { 

var window: UIWindow? 
let gcmMessageIDKey = "gcm.message_id" 
var tokenExists = false 

override init() { 
    super.init() 

    #if DEVELOPMENT 
     print("Development Mode Started") 
     let filePath = Bundle.main.path(forResource: "GoogleServiceDev-Info", ofType: "plist") 
     guard let fileopts = FirebaseOptions.init(contentsOfFile: filePath!) 
      else { assert(false, "Couldn't load config file") } 
     FirebaseApp.configure(options: fileopts) 
    #else 
     print("Production Mode Started") 
     FirebaseApp.configure() 
    #endif 

} 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    Messaging.messaging().delegate = self 
    IQKeyboardManager.sharedManager().enable = true 


    if #available(iOS 10.0, *) { 
     // For iOS 10 display notification (sent via APNS) 
     UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate 

     let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] 
     UNUserNotificationCenter.current().requestAuthorization(
      options: authOptions, 
      completionHandler: {_, _ in }) 
    } else { 
     let settings: UIUserNotificationSettings = 
      UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) 
     application.registerUserNotificationSettings(settings) 
    } 

    application.registerForRemoteNotifications() 
    Fabric.with([Crashlytics.self]) 

    return true 
} 

func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) { 
    print("Firebase registration token: \(fcmToken)") 
} 
func applicationWillResignActive(_ application: UIApplication) { 
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 
} 

func applicationDidEnterBackground(_ application: UIApplication) { 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 

} 

func applicationWillEnterForeground(_ application: UIApplication) { 
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
} 

func applicationDidBecomeActive(_ application: UIApplication) { 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    application.applicationIconBadgeNumber = 0 
    let token = Messaging.messaging().fcmToken 

    if token != nil { 
     tokenExists = true 
     let currUser = Auth.auth().currentUser?.uid 
     if currUser != nil { 
      let ref = FBDataservice.ds.REF_CURR_USER.child("notificationTokens") 
      let val = [token! : tokenExists] as [String : Any] 
      ref.setValue(val) 
     } 

    } 

    print("FCM token: \(token ?? "")") 

} 

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { 
    print("ADX: Hey") 
    if let messageID = userInfo[gcmMessageIDKey] { 
     print("Message ID: \(messageID)") 
    } 

    print("foreground ------------------------ \(userInfo)") 
} 

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], 
       fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { 
    print("ADX: Hey2") 

    if let messageID = userInfo[gcmMessageIDKey] { 
     print("Message ID: \(messageID)") 
    } 

    if Auth.auth().canHandleNotification(userInfo) { 
     completionHandler(.noData) 
    } 
    print("foreground ------------------------ \(userInfo)") 
    completionHandler(UIBackgroundFetchResult.newData) 
} 



func applicationWillTerminate(_ application: UIApplication) { 
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
} 

} 


@available(iOS 10, *) 
extension AppDelegate : UNUserNotificationCenterDelegate { 

// Receive displayed notifications for iOS 10 devices. 
func userNotificationCenter(_ center: UNUserNotificationCenter, 
          willPresent notification: UNNotification, 
          withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 
    let userInfo = notification.request.content.userInfo 

    // With swizzling disabled you must let Messaging know about the message, for Analytics 
    // Messaging.messaging().appDidReceiveMessage(userInfo) 
    // Print message ID. 
    if let messageID = userInfo[gcmMessageIDKey] { 
     print("Message ID: \(messageID)") 
    } 

    // Print full message. 
    print(userInfo) 

    // Change this to your preferred presentation option 
    completionHandler([]) 
} 

func userNotificationCenter(_ center: UNUserNotificationCenter, 
          didReceive response: UNNotificationResponse, 
          withCompletionHandler completionHandler: @escaping() -> Void) { 
    let userInfo = response.notification.request.content.userInfo 
    // Print message ID. 
    if let messageID = userInfo[gcmMessageIDKey] { 
     print("Message ID: \(messageID)") 
    } 

    // Print full message. 
    print(userInfo) 

    completionHandler() 
} 
} 

は、私は突然のアプリの通知を受けて停止しました。私はコンソールとクラウド両方の機能を働かせませんでした。

私はこのフォーラムで多数の質問を検索しましたが、答えは見つかりませんでした。

これを解決するための助けがあれば幸いです。

+0

アプリがフォアグラウンドでのみ、またはフォアグラウンドとバックグラウンドの両方で表示されない場合、通知は表示されませんか? – Hosny

+0

それは前に仕事をしていました。突然止まった。サンプルプロジェクトを試しました。それはそこで動作しますが、これは全く動作しないようです。私は4日間で打ち上げを開始し、これは動作を停止しました。 –

+0

私はGoogleのファイル名はGoogleService-Info.plistであるべきだと思います – Hosny

答えて

0

私は最終的にfirebaseサポートに連絡し、didFinishLaunchingWithOptions()でFirbaseApp.configure()を移動しなければならなかったことが判明しました。

関連する問題