2017-12-22 11 views
0

プッシュ通知に問題があります。私たちは、Firebase for Push Notificaionsを使用しています。問題は1つのiPhoneでPushNotificationsを正常に受信できても、別のiPhoneでPushNotificationsを取得できないことです。 AndroidでNotificationsを正しく取得しています。PushNotificationsがiOSで正しく動作しない(確実に)

私がやっていることは、同じアカウントからのサインインとプッシュ通知の試行です。何が起こっているのは、私のiPhone 5S上のすべてのアンドロイドの携帯電話を取得していることです。私のiPhone 6ではほとんどありません。

接続を設定するためにAppDelegateで使用されるコードです。

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { 
    InstanceID.instanceID().setAPNSToken(deviceToken, type: InstanceIDAPNSTokenType.sandbox) 
} 

@objc func tokenRefreshNotification(notification: Notification){ 
    print("entered tokenRefreshNotification") 
    let refreshedToken = InstanceID.instanceID().token() 
    if refreshedToken != nil{ 
     UserDefaults.standard.setValue(refreshedToken, forKey: "token") 
    } 
    //UserDefaults.standard.setValue(refreshedToken, forKey: "token") 
    print("Instance ID token: \(String(describing: refreshedToken))") 
    connectToFCM() 
} 


func connectToFCM(){ 
    Messaging.messaging().connect { (error) in 
     if error != nil{ 
      self.print("Unable to connect to FCM \(String(describing: error))") 
      return 
     } 
     self.print("connected to FCM") 
    } 
} 

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { 
    print("application did receive remote notification") 
    print(userInfo) 
    let notification = UILocalNotification() 
    notification.fireDate = Date() 
    let notificationType = (userInfo["type"] as! String).lowercased() 

    switch notificationType { 
    case "alert" : 
     print("Show notifications and save in the notifications list.") 
     notification.alertBody = userInfo["message"] as? String 
     //code for saving to user defaults 
     if var notifications = userDefaults.value(forKey: keys.notificationsList) as? [String] { 
      if let notificationString = notification.alertBody{ 
       notifications.append(notificationString) 
       userDefaults.setValue(notifications, forKey: keys.notificationsList) 
      } 
     } else{ 
      //in case of empty notificationList 
      if let notificationString = notification.alertBody{ 
       let notifications = [notificationString] 
       userDefaults.setValue(notifications, forKey: keys.notificationsList) 
      } 
     } 

     //notifications.append(notification.alertBody) 
     UIApplication.shared.scheduleLocalNotification(notification) 
    case "advertisement" : 
     print("Just show the notification and do nothing else.") 
     notification.alertBody = userInfo["message"] as? String 
     UIApplication.shared.scheduleLocalNotification(notification) 
    case "cleardb": 
     print("Clear everything from Database, but not logout user.") 
     notification.alertBody = "All data from database had been wiped" 
     UIApplication.shared.scheduleLocalNotification(notification) 
    case "update_device": 
     print("device_data has been updated so download devices info again") 
    case "logout": 
     print("logout the user") 
     Functions.functions.wipeUserDefaults() 

     notification.alertBody = "Logged out of Ryoking" 
     UIApplication.shared.scheduleLocalNotification(notification) 
    default: 
     print("lol") 
    } 
} 


func application(received remoteMessage: MessagingRemoteMessage) { 
    print("application received remote message") 
    print(remoteMessage.appData) 
} 

答えて

関連する問題