phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

no valid 'aps-environment' #1408

Open js12690 opened 7 years ago

js12690 commented 7 years ago

I am using plugin version of push notification (1.8.4) and create build using phonegap build with cli 6.3.0. Build created successfully but when test application on IOS 10.1.1 got following error message

no valid 'aps-environment' entitlement string found for application

I am using following code. Please help me as soon as possible

var push = PushNotification.init({ android: { senderID: "12345679" }, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' }, ios: { alert: "true", badge: "true", sound: "true" }, windows: {} });

push.on('registration', function(data) { alert(data.registrationId); });

push.on('notification', function(data) { // data.message, // data.title, // data.count, // data.sound, // data.image, // data.additionalData });

push.on('error', function(e) { // e.message });

clearminds commented 7 years ago

Update to 1.9.x - that fixes it

avishaan commented 7 years ago

@clearminds , 1.9x says it requires >= 6.4.0 which it doesn't seem that @js12690 has. @js12690 I wonder if you are using Meteor because of the specific version you have. If so, what did you end up doing in order to get it to work? I am in a similar boat

avishaan commented 7 years ago

@js12690 this got me to the next step, may have been xcode related or an issue with my entitlements file pasted_image_12_6_16__2_54_pm

avishaan commented 7 years ago

also, you might want to do a quick double check of your certs. I recommend using https://github.com/noodlewerk/NWPusher to make sure everything is setup properly on that end

BrianHollander-NL commented 7 years ago

Same problem here: "no valid 'aps-environment' entitlement string found for application". But I won't be able to upgrade my cordova, so I can't upgrade to 1.9.1....

Any other ideas? I tried branching a version with the aps-enviironment configs in the plugin.xml, but that seems to do nothing.

Thanks for thinking with me.

nodefish commented 7 years ago

I'm experiencing the exact same problem in a very strange set of circumstances: "no valid 'aps-environment' entitlement string found for application upon registration.

It started since I upgraded the plugin to the latest version, as well as Cordova to 6.4.0, and attempted to build on PhoneGap Build. I then read that 1.9+ was not supported on PGB, so I reverted back to 1.8.4, but it wouldn't work even after reverting.

I don't understand what the problem could be. It's been working for months on plugin v1.8.4 and Cordova 6.3.1, just upgrading then downgrading back to the exact same version numbers again killed it. A full source-code rollback (with all plugins being tracked by version control) followed by rebuild didn't work, nor did recreating the provisioning profile in Apple's developer portal.

nodefish commented 7 years ago

Well, now it seems to be working! What I did was change the SENDER value in config.xml, and did not specify a plugin version:

<plugin name="phonegap-plugin-push" source="npm">
    <param name="SENDER_ID" value="different-name-than-before" />
</plugin>

I suspect PhoneGap Build might have been caching the build files. I definitely noticed it building significantly more slowly when making larger changes or introducing a new plugin. This would explain why rolling back the plugin version to one that previously worked did not resolve the issue.

edit: Spoke too soon. It looked like it was working (error message was gone) but push notifications do not arrive.

avishaan commented 7 years ago

@timeseriesBH did you try my fix? I was having the same issue and that's what fixed it for me

BrianHollander-NL commented 7 years ago

I would try, but I am generating the app through a service (OutSystems), so I don't use Xcode...

Jorij commented 7 years ago

Same problem here. I'm using PGB which doesn't support 1.9.x, so i cannot upgrade to that. Is there any solution to get it work with PGB before it starts to supports 1.9.x?

We should be updating some minor issues to our application, but this is preventing us to do it.

rgagne commented 7 years ago

Same problem; we use PGB, the entitlement is in the provisioning profile (also tried regenerating it) but we get "no valid 'aps-environment' entitlement string found for application" at registration.

Is there a solution or is it possible to port the fix to 1.8.x?

MBuchalik commented 7 years ago

As far as I can see in the changelog, version 1.9.0 of the push plugin added aps-environment to -Release.plist and -Debug.plist. I updated my config.xml to include these lines but this didn't help (I am getting the error message). Is there anything I am still missing? Maybe, we can find a way to "port" the necessary changes of 1.9.0 into the config.xml? My attempt was:

<config-file platform="ios" target="*-Release.plist" parent="aps-environment">
    <string>production</string>
</config-file>
<config-file platform="ios" target="*-Debug.plist" parent="aps-environment">
    <string>development</string>
</config-file>

So I think I am still missing something. But maybe, this isn't as easy as I initially thought...

rgagne commented 7 years ago

@MBuchalik; saw that too and also tried that change and a few different variations on the target attribute in the config.xml but also haven't been able to get it to work.

tonijn commented 7 years ago

I confirm that the solution suggested by @MBuchalik does not fix the issue.

tonijn commented 7 years ago

PR added that might resolve the issue. Change your config.xml plugin spec to

    <plugin name="phonegap-plugin-push" source="npm" spec="https://github.com/tonijn/phonegap-plugin-push#fix-aps-environment">
        <param name="SENDER_ID" value="99999"/> <!-- pgb -->
        <variable name="SENDER_ID" value="99999"/> <!-- cordova -->
    </plugin>

During build the aps-environment setting is added to two plist files. These plist files are automatically added in cordova-ios >= 4.3.0. These are not added in cordova-ios 4.2.0, which is the version currently used in PGB. However you can add the files manually using asset in your config.xml:

Not working. PR cancelled

rgagne commented 7 years ago

Just did a PGB build and that seems to fix the problem. Thank you!

js12690 commented 7 years ago

@rgagne : is it solved?

@tonijn : what is the final solution of this issue?

Please guys do something for his issue

Thanks in advanced

rgagne commented 7 years ago

@js12690 - Working for me. Builds on PGB with that tag and instead of the aps-environment error getting a success callback from the init() call. Also, successfully getting push notifications.

js12690 commented 7 years ago

@rgagne which phonegap-version you have used?

have you used solution that given by @tonijn ?

It means you have used version 1.9.2 for push notification plugin. am i right? so finally you got device token from 10.1.1 and please check which IOS you are using for test?

Thanks in advanced

rgagne commented 7 years ago

@js12690, yes I used the solution given by @tonijn (should have specified that). The version of plugin-push is the branched 1.8.4. I am using PhoneGapBuild set to cli-6.4.0; this would fail to build on 1.9.x because the actual phonegap version was 6.3.x according to the logs.

In my build log file is: Repository "https://github.com/tonijn/phonegap-plugin-push" checked out to git ref "fix-aps-environment" at "94b0cac". Installing "phonegap-plugin-push" at "1.8.4" for ios

My test device is iOS 10.1.1 and I am getting a device token.

rgagne commented 7 years ago

@js12690 - fyi looking at https://github.com/phonegap/phonegap-plugin-push/pull/1467 you'll need to use the latest cli in PGB if using that:

<preference name='phonegap-version' value='cli-6.4.0' />

js12690 commented 7 years ago

@rgagne - Thanks for your reply

Just confirm with you. My code is following. Please correct me if i am wrong

<preference name="phonegap-version" value="cli-6.4.0"/> <plugin name="phonegap-plugin-push" version="1.8.4" source="npm" spec="https://github.com/tonijn/phonegap-plugin-push#fix-aps-environment"> <param name="SENDER_ID" value="99999"/> <!-- pgb --> </plugin>

rgagne commented 7 years ago

@js12690 - sorry looks like the branch was deleted; solution won't work anymore

@tonijn - could you restore that? it actually worked fine for me on PGB as long as I bumped the cli version to the latest

js12690 commented 7 years ago

@tonijn - Please make a tag as it is. it is work for @rgagne

Thanks in advanced @tonijn

js12690 commented 7 years ago

@tonijn @rgagne @macdonst - I think there is some issue in PGB because week ago i have created one build that give me device token but now with same code i am trying to create build is not working for me. my code is same but before week it is work and now it is not. i have both ipa file (one is created week ago and second one is create yesterday). I am getting device token from one week ago file but unfortunately not get from file that created yesterday.

can you please check on it?

Thanks

rgagne commented 7 years ago

@js12690 fyi - my build also was working a week ago (roughly) and stopped working. I think something changed at Apple so that the aps-environment is required in the entitlements file. When I uploaded through iTunesConnect I'd get a warning (not an error) from Apple, but registration stopped working.

With the 1.8.4 branch that @tonijn created it started working again - looks like the fix is a change in the plugin's config file to add the correct entitlement string.

rgagne commented 7 years ago

@js12690 - to answer your question above about your code; spec and version do the same thing; not sure what the behavior is if you have both

<gap:plugin name="phonegap-plugin-push" source="npm" spec="https://github.com/tonijn/phonegap-plugin-push#fix-aps-environment">
    <param name="SENDER_ID" value="xxxxxx" />
</gap:plugin>
BrianHollander-NL commented 7 years ago

My version is working now in Debug and Release. I customised the 1.8.3. https://github.com/timeseriesBH/phonegap-plugin-push#v1.8.3.4

js12690 commented 7 years ago

Hello all I am getting device token from IOS 10.1.1 without change any single word in my code.

I am using following code

<preference name="phonegap-version" value="cli-6.3.0" /> `

</gap:plugin>`

I think there is some problem in PGB. if i am wrong then please guys test your app and let me know if you still got issue

Thanks in advanced

frederikbosch commented 7 years ago

Okay I think this is the fix for building with PGB. It works for us.

    <engine name="cordova" version=">=6.4.0"/>
    <engine name="cordova-ios" version="~4.3.0"/>

    <plugin name="phonegap-plugin-push" source="npm" spec="https://github.com/frederikbosch/phonegap-plugin-push#fix-aps-environment">
        <param name="SENDER_ID" value="99999"/> <!-- pgb -->
        <variable name="SENDER_ID" value="99999"/> <!-- cordova -->
    </plugin>

So you need cordova cli 6.4.0, cordova ios and 4.3.0 and the fix from PR #1469. And then you can get push working with Phonegap Build.

rgagne commented 7 years ago

The new branch provided by @frederikbosch is also working for me.

macdonst commented 7 years ago

@js12690 can you try 1.9.x on PGB now? I believe the issue on the build server has been resolved.

ralphlenssen commented 7 years ago

My phonegap build is still not working with 1.9.2. While I do use 6.4.0 in the config xml and see that this is used on the phonegap build page.

Installing "phonegap-plugin-push" at "1.9.2" for ios Plugin doesn't support this project's cordova version. cordova: 6.3.2, failed version requirement: >=6.4.0 Skipping 'phonegap-plugin-push' for ios

stib commented 7 years ago

I get this same error "no valid 'aps-environment' entitlement string found for application" - I am using cordova 6.4.0 and phongeap-plugin-push 1.9.2

I am not familiar with PGB and so I don't believe am using that. My platform/ios/.entitlements file has the aps-environment entry

    <key>aps-environment</key>
    <string>development</string>

The plugin.xml file has the changes from 1469 commit

    <config-file target="*-Debug.plist" parent="aps-environment">
      <string>development</string>
    </config-file>
    <config-file target="*-Release.plist" parent="aps-environment">
      <string>production</string>
    </config-file>

This was all working fine at one point and then something changed which started giving this error - part of what changed was the renewal of my Apple dev account and I had to rebuild my provisioning profiles. I have spent quite some time reading through articles trying to figure this out but don't quite understand how to resolve this. Appreciate any help and pointers.

Thanks.

chr4ss1 commented 7 years ago

https://github.com/fastlane/fastlane/issues/6544

For xcode8+ you have to manually add aps-environment entitlement to the entitlements file. Some plugins (namely phonegap-plugin-push v1.9.0+) already do it automatically.

There is also a second problem, the entitlement files can get conflicted. I suggest you to view the entitlement file location in your ios project. It should be Entitlements-Release.plist and Entitlements-Debug.plist.

There are some plugins that can create their own entitlement files, and then ios starts to use them by default which then ignores the "real" entitlement files.

There's also a conflict with the custom-config-file plugin

You can read more about here:

https://github.com/nordnet/cordova-universal-links-plugin/issues/8

https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking/issues/299

ccorcos commented 6 years ago

I have a "before_compile" hook that fixes this for me. It just reads and overwrites the entitlements file.

const plist = require("plist")
const glob = require("glob")
const shell = require("shelljs")
const path = require("path")
shell.set("-e")

module.exports = context => {
    // Find the entitlements file using a pattern match
    const entitlementsGlob = path.join(
        context.opts.projectRoot,
        "platforms/ios/*/Resources/*.entitlements"
    )
    const entitlementsFile = glob.sync(entitlementsGlob)[0]

    // Read the entitlements file and parse into json
    const plistProperties = plist.parse(shell.cat(entitlementsFile).toString())

    // Set the Push Notifications capability
    const key = "aps-environment"
    // Apparently we should always set it to development and Xcode will set it to production appropriately
    // https://stackoverflow.com/questions/39625258/xcode-8-aps-environment-entitlement-wont-set-to-production
    const value = "development"
    plistProperties[key] = value

    // Write the file back
    shell.ShellString(plist.build(plistProperties)).to(entitlementsFile)
}
pgcan commented 6 years ago

@ccorcos , thanks for giving a right direction to this error because none of the solution mentioned worked for me.

I tried creating a hook using your code but that doesn't make any change in entitlement file. Then I manually made the change (adding aps-environment key) in entitlement file then also I got same "no valid aps-env" error. At last when I manually made change in Entitlements-Debug.plist file then it worked. Now I need to figure out how to update this plist file using hook.

Please Let me know if you made any change in your hook code after posting code snippet here. Or share if you have any other suggestion.