简体   繁体   中英

Cordova app that doesn't use push notifications: “Missing push notification entitlement”

We've got a Cordova based iOS app that does not use push notifications. As of Cordova 3.5.0, each submission we have made to the app store results in an email informing us that our app includes API used to register with Apple's Push Notification Service, but doesn't have push notification entitlement.

The app has been accepted each time, as we don't actually use push notifications for anything. However, I would like to avoid triggering this warning in case Apple decides to change their policy as to whether these API references are acceptable.

We did not experience the issue with prior versions of Cordova, and have done no work in Objective-C ourselves. Is this a known issue with Cordova 3.5? Searching has yielded some folks with similar problems but I've only found solutions for people wanting to add push entitlements, (rather than figure out where the Push API is being referenced and remove it). I took a look at the Cordova issues ML, but didn't find anything there. Any other leads that folks are aware of would be appreciated!

Plugins used:
org.apache.cordova.console
org.apache.cordova.device
org.apache.cordova.file
org.apache.cordova.inappbrowser
org.apache.cordova.media
org.apache.cordova.network-information
org.apache.cordova.splashscreen

Relevant email snippet, specific info replaced with [ ]:

From: iTunes Store
Date: Wed, Sep 17, 2014 at 3:49 PM
Subject: iTunes Connect: Your app "[appName]" (Apple ID: [id]) has one or more issues
To: [developer]

Dear developer,

We have discovered one or more issues with your recent delivery for "[app]". Your delivery was successful, but you may wish to correct the following issues in your next delivery:

Missing Push Notification Entitlement - Your app appears to include API used to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement. If your app uses the Apple Push Notification service, make sure your App ID is enabled for Push Notification in the Provisioning Portal, and resubmit after signing your app with a Distribution provisioning profile that includes the "aps-environment" entitlement. See "Provisioning and Development" in the Local and Push Notification Programming Guide for more information. If your app does not use the Apple Push Notification service, no action is required. You may remove the API from future submissions to stop this warning. If you use a third-party framework, you may need to contact the developer for information on removing the API.

After you've corrected the issues, you can use Xcode or Application Loader to upload a new binary to iTunes Connect.

Regards,

The App Store team

HOW TO DO THIS VIA THE XCODE UI (6.1):

While commenting out the offending code in Classes\\AppDelegate.m will get your app approved, you want to continue benefitting from future Cordova upgrades so the best way to do this is to turn on the DISABLE_PUSH_NOTIFICATIONS symbol during compilation so this bit of code gets left out.

I come from a C# background so I understand conditional compilation but I am new to XCode so I had to do a bit of research finding out how to define compilation symbols via the UI.

Turns out the magic words are 'Preprocessor Macro'. This is how the you can accomplish this graphically (note that this the way its done in XCode 6.1):

在此输入图像描述

Hope this helps other people out there in same situation.

Krik is right ! I've found this API calls in /Classes/AppDelegate.m certainly generated by Cordova 3.5.

I din't tried it for the moment, but these lines can certainly be commented in xCode to avoid Apple's warnings.

- (void) application:(UIApplication *)application
   didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    // re-post ( broadcast )
    NSString* token = [[[[deviceToken description]
                         stringByReplacingOccurrencesOfString: @"<" withString: @""]
                        stringByReplacingOccurrencesOfString: @">" withString: @""]
                       stringByReplacingOccurrencesOfString: @" " withString: @""];

    [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotification object:token];
}

- (void)  application:(UIApplication *)application
    didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    // re-post ( broadcast )
    [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
}

Have you had the Push Plugin installed at some point? Sounds like you have the respective Code somewhere in your application package. I'd do a project-wide search for the specific API calls eg:

  • didRegisterForRemoteNotificationsWithDeviceToken
  • didFailToRegisterForRemoteNotificationsWithError

The dead code, files need to be removed.

Heres' the full documentation: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2

Both kirk and r121 are correct.

In more recent versions of Cordova, this offending code is now helpfully generated inside a wrapper of #ifndef DISABLE_PUSH_NOTIFICATIONS . All you need do is add -DISABLE_PUSH_NOTIFICATIONS to your compiler flags. That's set in target/Build Settings/Custom Compiler Flags/(both C and C++ release) for those building inside XCode.

In our build process, we have been blowing away and rebuilding the AppDelegate.m file a lot. The hack I use is:

 sed -i "" -e "s/ifndef DISABLE_PUSH_NOTIFICATIONS/if 0/" build/cordova/platforms/ios/gThrive/Classes/AppDelegate.m
 # That uses the os/x sed to not have push notifications in the app

which just makes the problem go away.

As Charles Merriam points out, newer versions of cordova-ios make it easy to disable touching push notifications by setting the preprocesor flag DISABLE_PUSH_NOTIFICATIONS. ( See bug history .)

You will need to cordova platform update ios , platform uninstall ios and platform install ios to get the new in AppDelegate.m. (Maybe there's a better way than blowing away the folder?)

I found a Cordova on_platform_add hook script that will edit project.pbxproj with that flag for you when you install the iOS platform. I needed to npm install xcode to get the hook script to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM