BranchMetrics / cordova-ionic-phonegap-branch-deep-linking-attribution

The Branch Cordova Ionic Phonegap SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://docs.branch.io/apps/cordova-phonegap-ionic/
MIT License
233 stars 146 forks source link

Issue with Missing Push Notification Entitlement #465

Closed LKaemmerling closed 4 years ago

LKaemmerling commented 6 years ago

Hello guys,

i wanted to start to use branch.io with my ionic app. I added it and on of course it works. But since i add the sdk, on every build i submit to the itunes store there comes an error from the app store:

Dear Developer,

We identified one or more issues with a recent delivery for your app, "Mein Hetzner". 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 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. Xcode 8 does not automatically copy the aps-environment entitlement from provisioning profiles at build time. This behavior is intentional. To use this entitlement, either enable Push Notifications in the project editor's Capabilities pane, or manually add the entitlement to your entitlements file. For more information, see https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/HandlingRemoteNotifications.html#//apple_ref/doc/uid/TP40008194-CH6-SW1.

After some debugging with the ionic dev team, it turns out, that this sdk has the same problem described here: https://ionic.zendesk.com/hc/en-us/articles/360001923973?input_string=ios+builds+-+missing+push+entitlement

Can you have a look into this? I must remove the sdk from the app since i can't release the app on ios with it :)

Thank you!

ethanneff commented 6 years ago

Hello @LKDevelopment,

Unfortunately, the Branch Cordova SDK does not use Push Notifications. We only use Associated Domains for URI Scheme deep linking.

screen shot 2018-05-21 at 7 56 18 am

Additionally, if you dig into your <APP_NAME>.entitlements file, you should see that this SDK does not add the aps-environment key.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>com.apple.developer.associated-domains</key>
    <array>
      <string>applinks:cordova.app.link</string>
      <string>applinks:cordova-alternate.app.link</string>
    </array>
  </dict>
</plist>

Are you using another plugin for Push Notifications? You might want to investigate that plugin.

Thanks,

LKaemmerling commented 6 years ago

Hello @ethanneff,

i use the one signal push plugin. Without the branch.io sdk it works without any error, but with the branch.io sdk there is the error, so it seems to be a error from the branch.io sdk :) The ionic support says the same, i think they could send more informations on this: @ionic-team @BrianIonic

ragunathans commented 6 years ago

Is there any update on this issue? We are experiencing the same problem. Did anyone solve this issue?

LKaemmerling commented 6 years ago

Nope, the only working solution was to leave branch.io out of the app.

ragunathans commented 6 years ago

So we can't use both branch and one-signal plugin together. Right?

Is there any other solution or plugin available to do the same?

LKaemmerling commented 6 years ago

Yeah it isn't possible together... I can't find an other solution so we leaved the feature out....

matthew-valenti commented 6 years ago

Thanks for posting. I have this issue too. Adding additional information in the hope that this issue can be resolved.

In my case, creating binaries with IonicPro results in "Missing Push Notification Entitlement" and breaks the push notifications feature. However, I created a local environment to replicate the issue and surprisingly it's working (in development). I've confirmed that both deep links and onesignal push notifications are working. I don't know why building on my local is different to building on IonicPro. Building locally doesn't work for our team so I'm still working on a final solution.

Ionic:
   ionic (Ionic CLI)  : 4.0.0-rc.9
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.9
Cordova:
   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : ios 4.5.4
System:
   ios-deploy : 1.9.2
   NodeJS     : v8.9.4 (/Users/matthew/.nvm/versions/node/v8.9.4/bin/node)
   npm        : 5.6.0
   OS         : macOS High Sierra
   Xcode      : Xcode 9.4.1 Build version 9F2000

There were two key things that where needed to make this work.

  1. Our provisioning profiles in developer.apple.com where marked invalid. Re-saving them in developer.apple.com made them active again. IonicPro had to be updated with these new development and distribution profiles.
  2. I still can't figure out how to update associated domains automatically/correctly. In theory, adding this to config.xml should work (but doesn't).
<edit-config file="*-Debug.plist" mode="merge" target="com.apple.developer.associated-domains">
    <array>
        <string>applinks:53es.app.link</string>
        <string>applinks:53es-alternate.app.link</string>
        <string>applinks:53es.test-app.link</string>
        <string>applinks:53es-alternate.test-app.link</string>
    </array>
</edit-config>
<edit-config file="*-Release.plist" mode="merge" target="com.apple.developer.associated-domains">
    <array>
        <string>applinks:53es.app.link</string>
        <string>applinks:53es-alternate.app.link</string>
        <string>applinks:53es.test-app.link</string>
        <string>applinks:53es-alternate.test-app.link</string>
    </array>
</edit-config>

I tried every combination of things I could think of or find online but XCode would never include these domains in the final binary. It worked, if I pasted these domains directly into the MyAppName.entitlements file (in the root).

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>aps-environment</key>
    <string>development</string>
    <key>com.apple.developer.associated-domains</key>
    <array>
     <!-- Existing strings -->
      <string>applinks:myappname.app.link</string>
      <string>applinks:myappname-alternate.app.link</string>
     <!-- Strings I added manually. -->
      <string>applinks:53es.app.link</string>
      <string>applinks:53es-alternate.app.link</string>
      <string>applinks:53es.test-app.link</string>
      <string>applinks:53es-alternate.test-app.link</string>
    </array>
  </dict>
</plist>

I noticed that the applinks:myappname were always being generated but I'm not using a custom domain with Branch.io. So I changed config.xml to use the assigned domain "53es".

<branch-config>
    <branch-key value="key_live_..." />
    <uri-scheme value="myappname" />
    <link-domain value="53es.app.link" />
    <ios-team-release value="XFN..." />
</branch-config>

Branch.io then generated the following. Note the missing test domains. I'm not sure how to resolve that. But at least this allowed a binary to be successfully generated without manually updating.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>aps-environment</key>
    <string>development</string>
    <key>com.apple.developer.associated-domains</key>
    <array>
      <string>applinks:53es.app.link</string>
      <string>applinks:53es-alternate.app.link</string>
    </array>
  </dict>
</plist>
matthew-valenti commented 6 years ago

This hack worked in Ionic3 for creating an iOS binary using IonicPro. Both push notifications and branch.io deep links are confirmed working. This also seems to confirm that branch.io somehow removes this entitlement during a build. Hopefully, someone from the branch.io team can resolve this.

Note that the key difference between an IonicPro build and our local build is that IonicPro adds the ios platform on the fly during the build process.

/ios_push_entitlement_hack.sh

#!/bin/bash
if grep -q aps-environment platforms/ios/MyAppName/Resources/MyAppName.entitlements; then
  echo "Push notification entitlement already exists."
else
  echo "Push notification entitlement added."
  sed -i '' '/^[[:space:]]*<dict>/a\'$'\n''\'$'\t''<key>aps-environment<\/key>\'$'\n''\'$'\t''<string>development<\/string>\'$'\n''' platforms/ios/MyAppName/Resources/MyAppName.entitlements
fi

config.xml

<platform name="ios">
   <hook src="ios_push_entitlement_hack.sh" type="after_platform_add" />
sequoiaat commented 6 years ago

Hello,

In branch SDK we do not use push notifications, neither in code nor in XCode settings. Our findings are as follows:

  1. Created a sample ionic app and integrated branch SDK into it. Submitted to iTunes. Accepted successfully.
  2. Added “one signal push” plugin into the project and submitted to iTunes. “Missing Push Notification Entitlement” error occurs.
  3. Removed “one signal push” plugin from the project and submitted to iTunes. Accepted successfully! We are enabling push notification in XCode only for “one signal push” plugin as follows.

    1. In XCode from “Capabilities”, enable “Remote Notification” from “Background Mode”
    2. Enable push notification at the time of certificate creation

Please note that while using push notification, iTunes could throw this type of error if we do not do as follows: Open the project in Xcode. Select your App from the menu Target. Go to “Code Signing Entitlements” in “Build settings” in Target and check the path of the entitlement.

Thanks

LKaemmerling commented 6 years ago

Guys the problem is that you overwrite the entitlement completely, not that you use push notifications or everything else. The way you overwrite the entitlement looks wrong. But okay, when you say "Not our problem", then Branch is not the right solution for Ionic Developers.

Sarkar commented 6 years ago

@LKDevelopment sorry about this -- we're gonna fix the overwriting of the entitlements.

sequoiaat commented 6 years ago

@LKDevelopment @matthew-valenti

Branch sdk currently sets the code signing entitlements differently in App_Name.entitlements file which is inside the Resource folder (under the root folder).

It does not use the App_Name.entitlements file in the root folder for this purpose. As a result when we archive the app, it takes the configuration from inside the Resource folder, where the aps-environment key is not present. (One Signal plugin is unaware of the Resource folder) and hence you are facing this issue.

A temporary workaround for this issue is to manually edit the code signing entitlement, that is the Entitlements-release.plist file in the root folder.

mkeefe commented 5 years ago

I am facing this issue as well which is now breaking a production app. I'm not sure what @sequoiaat is referring to as the main *.entitlements file is altered as well. I suspect I could write a post-hook that will edit the entitlements file but why is this happening? What is the official solution?

Harjot1Singh commented 5 years ago

I came across the same thing (using Cordova 9), also using OneSignal/push entitlements.

As far as I understand, I previously only had Entitlements-Debug.plist and Entitlements-Release.plist files for entitlements, which contains the correct keys for push from OneSignal and associated domains.

This plugin writes to [APP_NAME].entitlements file, and the Resources/[APP_NAME].entitlements, which only contains the associated domain keys. It also modifies the location of the entitlements file

Doing a diff between with branch-sdk installed and without results in the notable differences of:

Only in cordova-branch/platforms/ios/[APP_NAME]: [APP_NAME].entitlements

Only in cordova-branch/platforms/ios/[APP_NAME]/Resources: [APP_NAME].entitlements

Files cordova/platforms/ios/[APP_NAME]/Entitlements-Debug.plist and cordova-branch/platforms/ios/[APP_NAME]/Entitlements-Debug.plist differ

Files cordova/platforms/ios/[APP_NAME]/Entitlements-Release.plist and cordova-branch/platforms/ios/[APP_NAME]/Entitlements-Release.plist differ

therefore I am convinced that this plugin is doing something unusual with respect to standard Cordova practice (the last two modifications are correct).

See https://github.com/nordnet/cordova-universal-links-plugin/issues/8#issuecomment-289472886 for a similar issue.

Related to #252

echo-branch commented 4 years ago

This should be resolved in the latest release.