Skip to content

Instantly share code, notes, and snippets.

@naonya3
Created October 17, 2016 09:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naonya3/341ea95910126d979822a9364f04f5b3 to your computer and use it in GitHub Desktop.
Save naonya3/341ea95910126d979822a9364f04f5b3 to your computer and use it in GitHub Desktop.
iOS10でのAPNSの知見です

アプリを起動してない状態からPush通知から起動

UNUserNotificationCenterDelegateの

userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void)

を実装居ている場合は上記が呼ばれ、実装していない場合は

AppDelegateの

application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])

が呼ばれる

アプリ起動中にPushを受け取った場合

UNUserNotificationCenterDelegateの

userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void)

を実装している場合は上記が呼ばれ、実装していない場合は

AppDelegateの

application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)

が呼ばれる

アプリ起動中にPush通知を受け取った場合、Push通知を表示したい

func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.Alert, .Sound])
    }

画像とか出したい

UNNotificationServiceExtensionを作る必要があって特に調べてない 証明書周りがめんどくさそうだな!っておもってる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment