2016-10-04 2 views
0

푸시 알림을 위해 Swift 2.2에서 Swift 3.0으로 소스 코드를 업데이트했습니다. 그러나 나는 userinfo를 얻을 수 없다. nil을 반환합니다. 아무도 도와 줄 수 있습니까?알림 센터의 푸시 알림은 userinfo에서 nil을 반환합니다. - Swift3

override func viewDidLoad() { 
     super.viewDidLoad() 
     self.delegate = self 

     NotificationCenter.default.addObserver(self, selector: #selector(MenuViewController.remoteNotificationReceived(_:)), name: NSNotification.Name(rawValue: "PushNotificationMessageReceivedNotification"), object: nil) 

    } 

func remoteNotificationReceived(_ notification: Notification) 
    { 
     print("Notification:\(notification.userinfo)"); 
} 
+0

한번보기 http://stackoverflow.com/q 39382852/didreceiveremotenotification-not-called-ios-10/39383027 # 39383027 –

+0

사용자 정보를 보내려는 경우 NotificationCenter.default.post (이름 : notificationName, object : nil)에 아무 정보도 보내지 않습니다. – AleyRobotics

+0

이 NotificationCenter.default.post (이름 : notificationName, 개체 : SOME_USER_INFO_OBJ) – AleyRobotics

답변

1

패스 사용자 정보 사후 통지 : 나는 푸시 알림을 수신 어떤 행동을하고 싶지 기타의 ViewController에서

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { 

     // Define identifier 
     let notificationName = Notification.Name("PushNotificationMessageReceivedNotification") 

     // Register to receive notification 
     NotificationCenter.default.addObserver(self, selector: #selector(MenuViewController.remoteNotificationReceived), name: notificationName, object: userInfo) 

     // Post notification 
     NotificationCenter.default.post(name: notificationName, object: nil) 
    } 

: 여기에 애플 대리자에서

는 푸시 알림을 수신하기 이와 같이 : -

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { 

     // Define identifier 
     let notificationName = Notification.Name("PushNotificationMessageReceivedNotification") 

     // Register to receive notification 
     NotificationCenter.default.addObserver(self, selector: #selector(MenuViewController.remoteNotificationReceived), name: notificationName, object: userInfo) 

     // Post notification 
     NotificationCenter.default.post(name: notificationName, object: nil, userInfo :userInfo) 
    } 
관련 문제