13

I have a CI build machine running Xcode server and using a bot to generate a build, however the .ipa built via the bot is not being entitled to register for the APNS token.

Specifically, didFailToRegisterForRemoteNotificationsWithError gets called and there is a runtime warning of ""No valid 'aps-environment' entitlement string found for application".

However if I build the app on a separte development PC, or I build it actually on the CI machine independently of the bot then everything is fine.

I've used push notifications extensively in several apps so know that the message "No valid 'aps-environment' entitlement string found for application" always appears if the app has not been signed with the correct profiles. However I have absolutely 100% confirmed that the app is being built with the same profiles when running as part of the bot build to when I build it manually.

I also know that Xcode downloads provisioning profiles to different locations when running under the bot to when running for a user, and I also know that the bot runs as system and not the logged in user when I build manually. I have taken all these differences into consideration but am still unable to get the bot build to work.

What's more I have used this exact same CI machine to previously build this app using Jenkins (which also ran as system) enabled for push and it worked!

These is what I have done/checked:

1) Download the project manually to the desktop, open in Xcode and examine the signing identity and provisioning profiles being sued in the build settings. Build and run it manually using Xcode -> it works Download the project indirectly via the bot as part of its integration run. Open the project downloaded by the Bot in Xcode (the Xcode server downloads it to: /Library/Server/Xcode/Data/BotRuns//Cache/NNNN). Do the same thing, check the signing identity and provisioning profiles. THEY ARE IDENTICAL to those used when I build on the desktop

OK so the problem is not due to a difference in the actual signing identity and provisioning profiles being used.

2) When you run Xcode manually it downloads the provisioning profiles to location X, but the Bot downloads the provisioning profiles to location Y. So I have examined the contents of X and Y to make sure there is nothing missing from Y (if there was the build would actually fail however, which it doesn't).

To make absolutely sure they are identical I have copied the entire contents of X into Y and run the bot again (they don't get overriden by the bot) - So now the bot and the desktop builds are using the exact same copies of the profiles yet still there is a difference when the .ipa executes.

Incidentally the location of X is ~/Library/MobileDevice/Provisioning Profiles and that of Y is / Library/Server/Xcode/Data/ProvisioningProfiles.

3) When I build manually it is as the logged in user, but when the bot build it is as the system. So within the keychain I have tried copying all the certificates and keys from the user's keychain into the system keychain. Yes still it makes no difference, the .ipa created by the build bot fails to run properly while the build created manually via Xcode does run.

This is driving me mad and has wasted days already, what else could I have missed or could try to resolve this?

Any suggestions or ideas?

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • you may check for that if the app is build with release or debug mode, if you run through the xcode it will directly deploy the debug build, you try to preapre the ipa through xcode and then try to install that build in your device – CoolMonster Mar 03 '14 at 06:17
  • But if you create an archive via XCode that is built in release mode and that also gets created with the aps-environment entitlement in the .app whereas it is not in the bot build which is also a release build. So it is not varying based on debug versus release, it is still varying based on bot versus non bot. – Gruntcakes Mar 05 '14 at 00:03
  • Hi, did you ever solve this somehow? I'm having exactly the same problem with Xcode 6.2 only when Bot creates IPA (it works when it's manually created and provisioning profiles are the same for sure). I also don't really understand solution from accepted answer, but it seams to me that it's outdated (Xcode 5), I don't even have that entitlements file. – tadija Mar 19 '15 at 22:04
  • This is literally the only thing that's stopping complete CI solution, because if push notifications can't work with Xcode bots, it all has to be done manually. I'm out of ideas for workaround on this problem. – tadija Mar 19 '15 at 22:23

3 Answers3

6

enter image description here

I have found the exact cause, as to the reason behind the cause I don't know, thus I'm marking mine as the accepted answer as it is at least a workaround to anybody who encounters the same problem. I'm tempted to think the reason is due to a bug in the bot system which is mistakenly expecting there to be an entitlements file.

I've discovered that the reason the bot build fails is because the bot is not placing the aps-environment entitlement into the .app file even though that entitlement is within the embedded.mobileprovision. But XCode does insert it into the .app file if built manually or an archive is built.

Also I've found that I can force the bot to put the necessary entitlement and associated information into the .app file if I use an Entitlements.plist.

But this is using Xcode 5 - entitlement.plist files are a thing of the past, so it should not be necessary to use one just to force the bot to place the entitlement into the .app, hence why I suspect it might be a bot bug.

Jeremy Wiebe
  • 3,894
  • 22
  • 31
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • Same happens to me. Anybody found a better workaround? – Matej Balantič Apr 29 '14 at 12:13
  • @Matej I spent days and days investigating and researching this and unfortunately I didn't find any other workaround. I think a better place to find another workaround, if there is one, is the Apple iOS forum boards if anybody from Apple bothers to reply. Please let me know if you do find another solution. – Gruntcakes Apr 29 '14 at 15:15
  • I didn't, but entitlements file helped. – Matej Balantič May 16 '14 at 16:45
  • 1
    What do you put in the entitlements file? I'm having a hard time finding the right keys and values... – Bob Vork Oct 20 '14 at 08:31
  • I've edited the answer to include my entitlements.plist, which I think (but can't remember) Xcode created automatically, rather than me creating it by hand. – Gruntcakes Oct 20 '14 at 18:19
  • Have you tried this with Xcode 6? Having the same problem. – kevboh Mar 03 '15 at 15:59
  • Its just a .plist file so you can use Xcode to create one - File | New | File | Resource | Property List. – Gruntcakes Mar 20 '15 at 15:11
0

Are you tried to unzip your .ipa and check embedded.mobileprovision they should be the same. Also just for sure check that you not use developer profile to release build in bot/xcode.

sage444
  • 5,661
  • 4
  • 33
  • 60
0

Shooting in the dark:

Although you said that the provisioning profile works great when you are running the build manually, have you tried creating a new provision profile from scratch and use that on the CI build machine using the bot?

Segev
  • 19,035
  • 12
  • 80
  • 152
  • Thanks for your answer. Yes I've tried that too. I'm currently in the process of deleting everything in the system keychain to clear it all out and reconstructing it to see if that has any effect. I have a very vague recollection of a problem from a few years ago about keys/certificates in the keychain interferring with each other, so that's my current line of investigation. Hope it solves things – Gruntcakes Feb 25 '14 at 17:10