2017-09-26 12 views
0

이상한 문제가 있습니다. 아래 코드를 사용하여 didFinishLaunchingWithOptions 내에서 원격 알림 승인을 요청하면 내 서버 (Firebase Messaging)에서 밀어 넣기 원격 알림을받을 수 있지만 나중에 승인을 요청하려고 할 때 안쪽 didFinishLaunchingWithOptions ' 통지를받을 수 없습니다.앱의 수명주기에서 다른 시간에 원격 알림 인증을 요청 하시겠습니까?

출시시 승인을 요청하고 싶지 않습니다. 예를 들어 사용자가 로그인 한 후 승인을 요청하고 싶습니다.

애플 문서는 말한다 :이 문제에

Always call this method before scheduling any local notifications and before registering with the Apple Push Notification Service. Typically, you call this method at launch time when configuring your app's notification support. However, you may call it at another time in your app's life cycle, providing that you call it before performing any other notification-related tasks.

// For iOS 10 display notification (sent via APNS) 
UNUserNotificationCenter.current().delegate = self 

let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] 

UNUserNotificationCenter.current().requestAuthorization(
      options: authOptions, 
      completionHandler: {_, _ in }) 

UIApplication.shared.registerForRemoteNotifications() 

어떤 제안/솔루션?

앱 정보 : 배포 대상 : 아이폰 OS 10.3 iOS 기기 : 아이폰 OS와 아이폰 OS 10/아이폰 7 아이폰 6 그래서 여기에 11

+0

여기서 다른 지점은 어디입니까? – TNguyen

+0

무슨 뜻이야?! – Jad

+0

또 어디서 권한 부여를 요청합니까? 또한 궁금한 점이 있다면 나중에 왜 다시 등록해야합니까? 아니면 나중에 등록하길 원합니다 – TNguyen

답변

1

내가 그것을 해결 방법은 다음과 같습니다 나는 원격 등록 내 didFinishLaunchingWithOptions에서

을 다음과 같은 알림 :

UNUserNotificationCenter.current().delegate = self 
UIApplication.shared.registerForRemoteNotifications() 

그런 다음 나중에 예를 들어 사용자가 로그인 한 후 다음 방법을 호출하여 인증을 요청합니다.

func reqeust() { 
     // For iOS 10 display notification (sent via APNS) 
     let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] 

     UNUserNotificationCenter.current().requestAuthorization(
      options: authOptions, 
      completionHandler: {_, _ in 



     }) 

    } 
+0

문서에서 말하는 것과 달리 실제로는 registerForRemoteNotifications 다음에'requestAuthorization'을 호출합니다. 이 방법으로 토큰을 얻었습니까? – NeoWang

+0

저는 Firebase 원격 알림을 사용하고 있습니다. 따라서 사용자가 인증을 요청하지 않았더라도 어쨌든 얻었습니다. Firebase를 사용하지 않는다면 권한 부여를 요청하면 알게 될 것입니다. – Jad