升级到Swift 3.0后未从Azure接收APNS消息
在将我的应用程序更新到Swift 3之后(这是一次多么好的体验!)-我知道由于iOS10中的更改,我必须重新编写通知代码 使用这个有用的资源-我能够重新编码,我得到了一个有效的连接 我还修改了项目的功能,添加了1)通知和2)后台模式/远程通知 但是,当我通过Azure的“测试发送”功能发送测试消息时,我没有收到它。 以下是我的AppDelegate中的相关代码:升级到Swift 3.0后未从Azure接收APNS消息,swift,azure,apple-push-notifications,swift3,Swift,Azure,Apple Push Notifications,Swift3,在将我的应用程序更新到Swift 3之后(这是一次多么好的体验!)-我知道由于iOS10中的更改,我必须重新编写通知代码 使用这个有用的资源-我能够重新编码,我得到了一个有效的连接 我还修改了项目的功能,添加了1)通知和2)后台模式/远程通知 但是,当我通过Azure的“测试发送”功能发送测试消息时,我没有收到它。 以下是我的AppDelegate中的相关代码: var window: UIWindow? func application(_ application: UIApplicati
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Register for remote notifications
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
if error == nil{
UIApplication.shared.registerForRemoteNotifications()
}
}
}
else {
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
UIApplication.shared.registerForRemoteNotifications()
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
let hub: SBNotificationHub = SBNotificationHub.init(connectionString: APISettings.Instance.notificationHubEndpoint, notificationHubPath: APISettings.Instance.notificationHubName)
hub.registerNative(withDeviceToken: deviceToken, tags: nil) { (error) -> Void in
if (error != nil){
print("Error registering for notifications: %@", error)
} else {
print("Registration ok")
}
}
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error)
{
print("Error = ",error.localizedDescription)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print(userInfo)
}
// MARK: UNUserNotificationCenter Delegate // >= iOS 10
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("User Info = ",notification.request.content.userInfo)
completionHandler([.alert, .badge, .sound])
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("User Info = ",response.notification.request.content.userInfo)
completionHandler()
}
任何帮助都将不胜感激。尝试在didFinishLaunchingWithOptions和clean>运行应用程序时调用此功能 func注册表通知() { UIApplication.sharedApplication() let application=UIApplication.sharedApplication() if application.respondsToSelector(#selector(UIApplication.registerUserNotificationSettings(:)) { func应用程序(应用程序:UIApplication,didRegisterUserNotificationSettings notificationSettings:UIUserNotificationSettings){
尝试在didFinishLaunchingWithOptions和clean>运行应用程序时调用此功能 func注册表通知() { UIApplication.sharedApplication() let application=UIApplication.sharedApplication() if application.respondsToSelector(#selector(UIApplication.registerUserNotificationSettings(:)) { func应用程序(应用程序:UIApplication,didRegisterUserNotificationSettings notificationSettings:UIUserNotificationSettings){
您是否在功能中启用了Keychain访问?感谢您的响应-是,Keychain已启用能否尝试设置从azure发送到High的推送通知的优先级您是否在功能中启用了Keychain访问?感谢您的响应-是,Keychain已启用能否尝试设置从azure发送的推送通知的优先级azure到High我看不出这是如何试图解决问题的。请详细说明。我看不到这是如何试图解决问题的。请详细说明。
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
}
}
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}