2016-10-24 5 views
2

Swift 3にアプリケーションをアップデートした後、私はiOS10の変更により通知コードを修正する必要があることを知りました。この便利なリソース使用Swift 3.0へのアップグレード後にAzureからAPNSメッセージを受信して​​いません

- 私は再コーディングすることができたと私は有効な接続

https://github.com/ashishkakkad8/Notifications10Swift/blob/master/Notifications10Swift/AppDelegate.swift

を取得していますが、私はまた、/ 1)の通知を追加し、プロジェクトのためCapabiltiesを改正し、2)バックグラウンドモードリモート通知。

しかし、Azureの「テスト送信」機能でテストメッセージを送信すると、受信しません。

ここに私AppDelegateから該当するコードです:

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() 
} 

は、任意の助けいただければ幸いです。

+0

あなたは能力のキーチェーンアクセスを可能にしましたか? –

+0

応答ありがとうございます - はい、KeyChainが有効です – KyriD

+0

紺碧から送られたプッシュ通知の優先度を高く設定することができます –

答えて

-1

試しにアプリ

FUNCのregisterNotification()

{

UIApplication.sharedApplication() LETアプリケーション= UIApplication.sharedApplicationを()を実行> didFinishLaunchingWithOptionsときれいにこの関数をコールします

if application.respondsToSelector(#セレクタ(UIApplication.registerUserNotificationSettings(_ :)))

{

 let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) 


     application.registerUserNotificationSettings(settings) 
     application.registerForRemoteNotifications() 

    } 

} 

FUNCアプリケーション(アプリケーション:のUIApplication、didRegisterUserNotificationSettingsのnotificationSettings:UIUserNotificationSettings){

if notificationSettings.types != .None { 
     application.registerForRemoteNotifications() 
    } 
} 
+0

これはどのように問題を解決しようとしていません。詳しく教えてください。 – ericosg

関連する問題