Pu sh уведомление не запускается автоматически в ios - PullRequest
0 голосов
/ 11 июля 2020

У меня есть уведомление pu sh в моем ios коде. Код в делегате приложения выглядит следующим образом:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
       FirebaseApp.configure()
        
        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self
            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
            // For iOS 10 data message (sent via FCM
            Messaging.messaging().delegate = self
        } else {
            let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
              application.registerUserNotificationSettings(settings)
        }
         
        application.registerForRemoteNotifications()
         
     
        Messaging.messaging().delegate = self
         let token = Messaging.messaging().fcmToken
          print("FCM token: \(token ?? "")")
      

        return true
    }
 
    
   
    
    func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
      print(fcmToken)
    }
    

    func application(
        _ application: UIApplication,
        didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
    ) {
        
    let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
        let token = tokenParts.joined()
        print("Device Token aaaa: \(token)")
        
        Messaging.messaging().apnsToken = deviceToken
        Messaging.messaging().setAPNSToken(deviceToken, type: .unknown)
        

        viewController?.updatetoken(token: deviceToken)
        
      
    }
    
    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        print("failed to register for remote notifications",error)
    }
    
    
        func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
            print("Firebase registration token didreceieve: \(fcmToken)")
            
            UserDefaults.standard.set(fcmToken, forKey: "fcmToken")
            let dataDict:[String: String] = ["token": fcmToken]
            NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
    
        }
 // For iOS 10 and later; do not forget to set up a delegate for UNUserNotificationCenter
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                didReceive response: UNNotificationResponse,
                withCompletionHandler completionHandler:
                   @escaping () -> Void) {
       let userInfo = response.notification.request.content.userInfo
        
         viewController?.receivedNotification(userinfo: userInfo as NSDictionary)
        

    }

    // For iOS versions before 10
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // If your application supports multiple types of push notifications, you may wish to limit which ones you send to the TwilioChatClient here
        
        
        print("userinfo is",userInfo)
        
        viewController?.receivedNotification(userinfo: userInfo as NSDictionary)

    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        
        print("Push notification received in foreground.")
         let userInfo = notification.request.content.userInfo
        
          completionHandler([.alert, .badge, .sound])
    }

Я добавил проект ios в firebase и добавил песочница и производственный сертификат p12 для него. Я попробовал уведомление с помощью облачных сообщений, выбрав идентификатор пакета из firebase, и я получил уведомление. Также я попробовал уведомление с помощью pu sh попробуйте использовать p12 и токен устройства, я получил уведомление. я не получаю уведомления автоматически из приложения, как в android. В чем может быть проблема в моем коде?

...