0
У меня было обновление с исходного кода от Swift 2.2 до Swift 3.0 для push-уведомления. Но я не могу получить userinfo. Он вернет нуль. Может ли кто-нибудь помочь?Push-уведомление в NotificationCenter return nil в userinfo - Swift3
Здесь в приложении делегат получил толчок уведомление:
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)
}
В других ViewController я хочу получил уведомление толчок и делать какие-то действия:
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)");
}
см. Этот раз http://stackoverflow.com/q uestions/39382852/didreceiveremotenotification-not-called-ios-10/39383027 # 39383027 –
Вы отправляете информацию о пользователе nil в NotificationCenter.default.post (имя: notificationName, object: nil) – AleyRobotics
, если вы хотите отправить информацию о пользователе. Сообщение должно быть например, NotificationCenter.default.post (name: notificationName, object: SOME_USER_INFO_OBJ) – AleyRobotics