2016-11-10 276 views
0

我的應用程序有:爲什麼「didRegisterForRemoteNotificationsWithDeviceToken」沒有被調用n swift 3,iOS 10,XCode 8?

APP ID - 推送通知啓用,
提供個人資料(開發) - 推通知啓用,
目標 - 能力 - 啓用推送通知,
目標 - 背景模式 - 背景取,遠程通知啓用

在的appDelegate 1. import UserNotifications

2. class AppDelegate: UIResponder, UIApplicationDelegate, UINavigationControllerDelegate, UNUserNotificationCenterDelegate

3. 

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    if #available(iOS 10.0, *) 
      { 
       let center = UNUserNotificationCenter.current() 
       center.delegate = self 
       center.requestAuthorization(options: [.badge, .sound, .alert], completionHandler: { (granted, error) in 
        if error == nil 
        { 


         //UIApplication.shared.registerForRemoteNotifications() 
         application.registerForRemoteNotifications() 
        } 
        else 
        { 
         print("\(error?.localizedDescription)") 

        } 
       }) 
      } 
      else 
      { 
       registerForPushNotifications(application) 
       // Fallback on earlier versions 
      } 
    } 

didRegisterForRemoteNotificationsWithDeviceToken是不會被調用,而不是didFailToRegisterForRemoteNotificationsWithError越來越通話

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { 

繼錯誤我得到的didFailToRegisterForRemoteNotificationsWithError

域= NSCocoaErrorDomain代碼= 3000「沒有有效的「aps-環境'應用程序的權利字符串「UserInfo = {NSLocalizedDescription =無效的'aps-environment'應用程序的權利字符串}

我錯過了什麼嗎?

+0

添加要在'didFailToRegisterForRemoteNotificationsWithError'收到錯誤。 –

+0

@NiravD我已經更新了我的問題,在執行中是否有任何缺失? – sss

+0

看看這一個http://stackoverflow.com/questions/27324020/no-valid-aps-environment-entitlement-string-found-for-application-on-app-store和這個http://stackoverflow.com/ questions/10987102/how-to-fix-no-valid-aps-environment-entitlement-string-found-for-application –

回答

1

我也面臨同樣的問題Xcode 8和我已經通過 選擇Capabilities->Push Notification->Add the Push Notifications entitlement to your entitlements file選項中的問題。

欲瞭解更多信息,請找到下面的截圖。

Screenshot

而且一旦你選擇,則選項授權文件添加到您的項目文件夾。請找到下面的截圖。

Screenshot

由於XCode 8,從當地的權利文件,而不是從你的蘋果開發者門戶網站創建的供應配置文件的權利設置。現在需要將權利添加到您的配置文件中的功能下的Xcode內部版本中。

希望它適合你!

+0

YES。我已經啓用了權利。我啓用了此功能,並在此之後創建了授權文件。我錯過了什麼? – sss

+0

然後我認爲在配置文件中有問題,請檢查它,因爲我沒有發現任何其他問題。 –

+0

在provosioning個人資料推送通知啓用,即使對於iOS 9我收到通知具有相同的提供資料,但不與iOS 10 ...這是可能的,如果提供配置文件不正確? – sss

0

當我更新到最新版本的XCode和Sierra時,我遇到了類似的問題。

  • 我在將該項目的相關Apple ID添加到 項目 - >首選項之後得到了修正,試試吧。
  • 我還進行了各種你所採取的步驟支持iOS的10

enter image description here