Missing Push Notification Entitlement

Just feeding back.

My app was accepted fine even with this error.

1 Like

Same issue here. I’m not using push notifications but I’m also getting this warning. Perhaps some faulty defaults in the new cordova-ios 3.7.0?

Hi,

I am not sure if this helps but I fixed the problem as follows:

  1. Create a hook to remove the offending functions from AppDelegate.m.
  2. Invoked the hook for the ios platform during “after_prepare” in config.xml.

HOOK: ios-remote-notification-fix.js

The hook looks like this. Please note that you will have to change MyApp in the fn setting to your app name.

#!/usr/bin/env node

// ================================================================
// Read the platforms/ios/<appname>/Classes/AppDelegate.m
// and comment out the following functions:
// 1. didRegisterForRemoteNotificationsWithDeviceToken
// 2. didFailToRegisterForRemoteNotificationsWithError
// ================================================================
var fs = require('fs');
var sys = require('sys')

sys.puts('');
sys.puts('# ================================================================');
sys.puts('# HOOK: ios-remote-notification-fix.js');
sys.puts('# ================================================================');

// The file to change (and its backup).
var fn = 'platforms/ios/MyApp/Classes/AppDelegate.m';
var fno = fn + '.orig';  // backup

// Make sure that this hook is re-entrant.
if (fs.existsSync(fn) && !fs.existsSync(fno)) {
    sys.puts('INFO: creating ' + fno);
    fs.writeFileSync(fno, fs.readFileSync(fn));
    fs.readFile(fn, function(err, data) {
        if (!data) {
            sys.puts('ERROR: could not read file: "' + fn + '"');
            process.exit(1);
        }
        sys.puts('INFO: read ' + fn);
        sys.puts('INFO:   ' + data.length + ' bytes');

        // Convert to lines for parsing.
        var lines = [];
        var line = '';
        for(var i=0; i<data.length; i++) {
            var ch = String.fromCharCode(data[i]);
            line += ch;
            if (data[i] == 10) {
                lines.push(line);
                line = '';
            }
        }
        if (line.length > 0) {
            lines.push(line);
        }
        sys.puts('INFO:   ' + lines.length + ' lines');
        
        // Filter out the functions in question using line parsing.
        var fcts = [ 'didRegisterForRemoteNotificationsWithDeviceToken',
                     'didFailToRegisterForRemoteNotificationsWithError'];
        var newlines = [];
        var start = 0;
        for(var i=0; i<lines.length; i++) {
            var line = lines[i];

            // See if one of the functions is found. If it is
            // we are one line beyond what needs to be filtered
            // out.
            //
            // Example:
            //
            //   - (void)                                 application:(UIApplication*)application
            //     didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
            // {
            //     // re-post ( broadcast )
            //     [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
            // }
            //
            var found = false;
            for(var j=0; j<fcts.length; j++) {
                if (line.indexOf(fcts[j]) >=0 ) {
                    found = true;
                    break
                }
            }

            // The function was found, ignore it.
            if (found) {
                // We are one past the lines to ignore.
                var end = i - 1;
                for(var j=start; j<end; j++) {
                    newlines.push(lines[j]);
                }
                
                // Skip the function code and reset start.
                for(; i<lines.length; i++) {
                    line = lines[i];
                    var j = line.indexOf('}');
                    if (j >= 0 && j <= 2) {
                        // + 2 because we know by inspection that there is
                        // a trailing empty line.
                        start = i + 2;
                        break;
                    }
                }
            }
        }
        for(var i=start; i<lines.length; i++) {
            var line = lines[i];
            // Handle the case where the last line does not end with a new line.
            if (line.indexOf('\n') < 0) {
                line += '\n';
            }
            newlines.push(line);
        }
        var newdata = newlines.join('');
        sys.puts('INFO: writing ' + fn);
        sys.puts('INFO:   ' + newdata.length + ' bytes');
        sys.puts('INFO:   ' + newlines.length + ' lines');
        fs.writeFileSync(fn, newdata);
    });
}

sys.puts('# ================================================================');
sys.puts('# DONE: ios-remote-notification-fix.js');
sys.puts('# ================================================================');

config.xml

The config.xml entry looks like this:

<platform name="ios">
  <hook type="after_prepare" src="hook_scripts/ios-remote-notification-fix.js" />
</platform>

Cheers,

Joe

4 Likes

Where in the config.xml should I insert this js file? Inside widget tag or outside widget tag?

Great Stuff, thanks Joe.

@Hughred22: outside. Usually, nothing goes outside a root tag in XML

For me the same problem today , i’ve opened also another post with other itunes connect problems

if there is something like “Your delivery was successful, but you may wish to correct the following issues in your next delivery” you don’t need to do anything.

you can create new Provisioning Profile for your app and download it. then validate the app again
source: http://stackoverflow.com/a/5719532/4019802

1 Like

In XCode find AppDeligate.m find and comment out this code:

    — (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];
}

Now when you submit you will not get this warning from Apple.

3 Likes

Unfortunately, this doesn’t work for me.
I’m doing remote build with Visual Studio and it seems, I can’t get VS to inject custom hooks into the cordova project.
My hooks folder lands in the App itself instead of in the Cordova project’s hook folder.
Any ideas on this?

Thx

Thanks for this. :smile:

According to stackoverflow this problem has persisted since Cordova 3.5 So if any Cordova persons is monitoring this thread could you please take appropriate action? Please…

They know about it over at the Cordova/PhoneGap forums. We’ve been talking about it for months.

Then I have to as why it is a problem still?

Hi, I am also facing same issue after immediately submitting my app to appStore. But my app status is still “Waiting For Review”. Do I need to submit new binary with changes or I should wait? If any one can give me suggestion the it would be helpful to me.

You don’t need to submit a new binary, no.

Did my solution but work for you?

Hi Jlinoff,

Thanks for the script, I managed to get the script to run but had to do the following:

  1. Rather than define the hook in the config.xml, I place the ios-remote-notification-fix.js file in “app/hooks/after_prepare”

  2. Within the “app/hooks/after_prepare” folder i ran: chmod -R 777 ios-remote-notification-fix.js

  3. Running cordova prepare ran the hook and so removed the unwanted lines of code!

Holly Schinsky has a useful post on Cordova hooks see: Three hooks your Cordova/PhoneGap project needs

Thanks!

Russell

1 Like

That’s great. I am glad that it is working. Using the default hooks structure is perfectly fine.

I am sorry to hear that explicitly defining hooks is not working for you. Try using the default hooks structure as defined by rusself9 below. Here is what he suggested:

  1. Rather than define the hook in the config.xml, place the ios-remote-notification-fix.js file in “app/hooks/after_prepare”
  2. Within the “app/hooks/after_prepare” folder run: chmod -R 777 ios-remote-notification-fix.js
  3. Running cordova prepare ran the hook and so removed the unwanted lines of code!

Thanks for your answer but I guess you missed that I’m working on Windows with Visual Studio and it seems that VS doesn’t know hooks (folder) itself.
The VS project itself is not in Cordova structure but during build it creates a folder called “bld” where it places the platform specific project folders in cordova structure.
So when I add a hooks folder in VS, it’s contents aren’t placed in the hooks folder of the cordova project, the whole folder is placed inside the www folder.

I tried manually adding the file to the hooks folder in the cordova project but failed somehow. Don’t know why exactly anymore. But I’ll give it a try next time I build for iOS. ATM I haven’t even a Mac here.
Maybe the way with the config.xml is the solution for me (what is the “working folder/path” in config.xml for referencing files??)… I’ll see…

But what I’m really curious about is why they don’t just remove the unnecessary lines of code in Cordova, shouldn’t be such a big deal…?!?

Initially I tough it was a problem with PhoneGap but today I tried to upload the app from Xcode and the problem is still there.

So I guess is a Cordova bug.

Anyways, if you develop on OS X (and/or Linux) this should fix the issue – will try it before the next request to be approved on the Apple Store:

sed -i “” -e “s/ifndef DISABLE_PUSH_NOTIFICATIONS/if 0/” {PATH TO YOUR APP INSTALL ROOT}/platforms/ios/{YOUR APP NAME}/Classes/AppDelegate.m

Where:

  • {PATH TO YOUR APP INSTALL ROOT} is your app main folder – the one
    from within you launch: ionic build ios
  • {YOUR APP NAME} is the name you set in the config.xml <name> tags

If you are not using push notifications within your app, then add:

#define DISABLE_PUSH_NOTIFICATIONS

to the top of AppDelegate.m within /platforms/ios/{appname}/classes/appdelegate.m to fix the issue.

1 Like