0

My app has :

APP ID - push-notification enabled,
Provision Profile (Development) - push-notification enabled,
Target - capabilities - push-notification enabled,
Target - background mode - background fetch, remote notification enabled

In 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
            }
    }

but didRegisterForRemoteNotificationsWithDeviceToken is not get called instead didFailToRegisterForRemoteNotificationsWithError is getting call

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

Following error I'm getting at didFailToRegisterForRemoteNotificationsWithError

Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo={NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}

Is I am missing something?

Nirav D
  • 71,513
  • 12
  • 161
  • 183
New iOS Dev
  • 1,937
  • 7
  • 33
  • 67
  • Add error that you are getting in `didFailToRegisterForRemoteNotificationsWithError`. – Nirav D Nov 10 '16 at 06:16
  • @NiravD I have updated my question, is there anything missing in my implementation? – New iOS Dev Nov 10 '16 at 06:33
  • Check out this one http://stackoverflow.com/questions/27324020/no-valid-aps-environment-entitlement-string-found-for-application-on-app-store and this http://stackoverflow.com/questions/10987102/how-to-fix-no-valid-aps-environment-entitlement-string-found-for-application – Nirav D Nov 10 '16 at 06:33

2 Answers2

1

I am also face the same issue in Xcode 8 and I had resolved the issue by select the option in Capabilities->Push Notification->Add the Push Notifications entitlement to your entitlements file.

For more information please find the below screenshot.

Screenshot

And once you select the option then a entitlement file added to your project folder. Please find the below screenshot.

Screenshot

As XCode 8, the entitlements are set from your local entitlements file rather than from the provisioning profile you created on the Apple Developer Portal. The entitlements will now need to be added to your Xcode build under Capabilities in addition to in your provisioning profile.

Hope it works for you!!!

Ramkrishna Sharma
  • 6,961
  • 3
  • 42
  • 51
  • YES. I have already enabled entitlements. I enabled this and after that entitlement file is created. is I am missing something? – New iOS Dev Nov 10 '16 at 07:03
  • Then I thought there is a problem in provisioning profile please review it because I did not find any issues other than that. – Ramkrishna Sharma Nov 10 '16 at 07:11
  • In provosioning profile pushnotification is enabled, even for iOS 9 I am getting notification with same provision profile but not with iOS 10...is this possible if provision profile is not correct? – New iOS Dev Nov 10 '16 at 07:20
  • Then please review the link http://stackoverflow.com/questions/39532953/push-notifications-not-being-received-on-ios-10-but-working-on-ios-9-and-before which help you. – Ramkrishna Sharma Nov 10 '16 at 08:36
0

I ran to similar kind of problem when I update to latest version of XCode and Sierra.

  • I got this fixed after add the Apple ID related to that project under Project -> Preference as follow, Try it.
  • I also performed all the steps you have followed for supporting iOS 10.

enter image description here

Bharath
  • 2,064
  • 1
  • 14
  • 39