Sunday, January 20, 2013

Provisioning Profiles - a labor of love

Well, this provisioning profile thing has turned out to be quite a bear - as it always is. Yesterday, I found a post in stack overflow that seemed to be getting to the root of the issue. Today, I'm going to try to see if it works.

The first thing I'm doing is backing up the project (I know - I need to put it on git or svn).

Wait. I need to rename my device, because right now it's confusingly called "My Name's iPod" when it's an iPhone. Arghh.

I deleted my app profiles, but when I try to create a new one, it's showing up with the iPod name, though (as before) with the correct id for my iPhone.

Ok, I had to delete the old one, then added the device from Xcode's organizer view. A small victory, at least. It's showing up now as iPhone (which, btw, I renamed in organizer also just by double-clicking).

Ok, for grins I'm going use the assistant to create a provisioning profile.

At the launch:


"Introduction
To run an application you're developing for iPhone, iPad or iPod touch, you must have a Provisioning Profile and a Development Certificate installed on your device and your Mac. The Provisioning Assistant will guide you through the steps to create and install your Development Provisioning Profile and iOS Development Certificate."

So, the profile and dev cert have to be on *both* the device and the Mac. 

Ok, now select an app. 

That's good. The app name is "JlptVocabQuiz". 

Now,  choose an existing iPhone device - pick my iPhone (just renamed). 

Now, "Use your existing developer certificate".  Ah, it's all starting to make sense. This wizard really organizes the process nicely. 

Now:

"Name your Provisioning Profile

A Provisioning Profile is a collection of your App ID, Apple device UDID, and iOS Development Certificate that allows you to install your application on your device."

This is really nice. Pulling it all together. Now, I just need to give a name.

"Enter a common name or description for your Provisioning Profile using alphanumeric characters. The description you specify will be used throughout the Provisioning Portal to identify this Provisioning Profile."

Let's call "JlptProfileForIphone". 

"Step 1: Download

Download the Provisioning Profile to your Mac."

Ok, it's in the download folder:

"Step 2: Install
Connect your device to your Mac and drag the downloaded Provisioning Profile into the ‘Organizer’ window within Xcode. This will automatically install the .mobileprovision file in the proper folder."

Ok - should I clean out the provision profile entries from project file first? I think I will. 

Ok - new error. Problem with linking to flurry analytics. Delete all references and the library - and successful build!

Let's see if it runs on the device....

Took a couple of tries, but yes - finally the app on the iPhone. But - the mp3s aren't sounding. On to the next problem. 









Saturday, January 19, 2013

Getting down with Provisioning Profiles

So, I'm going to give an another crack at getting my programming to run on the 4s. So, last Jan 1, I ending up getting tangled up in a web of developer certificates, provisioning profiles, team certificate requests, organizer displays showing the wrong name and the right device, and so forth and so on until I was thoroughly lost. I'm still lost, but have no choice but to try to hack my way out of this digital forest. Do other people have this kind of trouble?

 Oh, yeah, one thing I did do was download Xcode 4.5, which was the one thing I did figure out I needed. Let's bring that up and see what happens when I try to run the app. Ok, when I bring up the app, I get a much clearer message than last time (I think): "Provisioning profile 'JLPT Vocabulary Quiz Development Profile' has expired".

So, I guess the provisioning profile is stored on my macbook, say on the keychain, or with the app, as opposed to on the device.The reason is that the phone is new, and therefore the provisioning profile couldn't be on my device.

 Ok, I went to organizer, and all the profiles related to my app were expired. I tried pressing the "renew" button for the profiles, but nothing. So, I'm just going to delete them. How could they have been on my iPhone anyway?

Ok, I just went to https://developer.apple.com/ios/manage/provisioningprofiles/index.action and deleted the profile there, but I still get the same error when I do a build on Xcode. What next? Wow. I think I might have screwed up with all my deleting. I saw an entry on SO that said you just have to right-click on your device in organizer and then just select "add device to profile". But - the profile is gone. I just deleted it. Rats.

So, now I think I have to recreate it.  Ok, in the provisioning portal, under provisioning, the developer tag, I selected "new profile'. I pasted the profile name in. For the app name, it gave me a list of app names to choose from. Three of them roughly match my app name, so I'm picking the one that looks most final (these are names I would've created before.

Wow. It's put the expired profile names that I deleted back in the list! Amazing. And the one I just tried to recreate now has a "pending" status. Let's refresh it. Active!

Ok, I think I need to download it now or something. Ok, when I download it, it hopped into the download folder, and I dragged to to the Xcode icon (btw, why don't they call it xCode? That spelling is so much more intuitive). Xcode automatically went to organizer after that, and now it says the profile is valid - let's try a build.

Nope. Not yet. Let's try the "add device to provisioning portal" again, since the profile was created with only the old iPod as the device.

Well, I tried doing the same thing with the other provision profile with my app name, and somehow the organizer was showing me the expired profiles again! (which I deleted).

Btw, I also modified the settings in Xcode so to add the profile name for signing on the app store, debug and whatever the other one is.

Ah, now at least I'm getting a different error message: "Provisioning profile '814FA14A-2A11-4447-BB5A-1CFE7AC042FC' can't be found" No idea why it's looking for that crazy string.

Ok, this SO entry looks *very* interesting (437 upvotes, never seen so many).

"Sometimes your xcode project file gets messed up, especially if you have an old project and first created it with an older version of xcode/iphone sdk. What you need to do is open up the project file in a text editor, search for the 'long string' from your error and manually erase that line. In fact, you should just go ahead and erase any line that points to any provisioning profiles. Then reopen the project in xcode, go to the settings and reselect your new profile. This clears up issues like that most of the time.

The lines that point to the provisioning profiles will look like this:
 PROVISIONING_PROFILE = "487F3EAC-05FB-4A2A-9EA0-31F1F35760EB"; "PROVISIONING_PROFILE[sdk=iphoneos*]" = "487F3EAC-05FB-4A2A-9EA0-31F1F35760EB";

also in the same thread:

"The .xcodeproj file is actually a directory, like an application bundle, If you right click it in finder, you can select show package contents, and then you will see several files inside (or in terminal just cd into it). The actual project file is the one in there with a .pbxproj extension. Once you open it with a text editor the lines you are looking for should start with 'PROVISIONING_PROFILE = or' '"PROVISIONING_PROFILE[sdk=iphoneos*]" ='. Delete all of those and then you should be good"

also:

"I found that, in addition to the above, I had to delete all of my profiles, re-download them from the provisioning portal, and reimport them into XCode. Then, in Build Settings / Code Signing, select the proper profile for all build configurations.

However, in Xcode 4.2 and later, there is a much easier way to access this text and select and delete it. In the Project Navigator on the left, select your project (the topmost line of the Project Navigator). Now simply choose View > Version Editor > Show Version Editor. This displays your project as text, and you can search for PROVISIONING and delete the troublesome line, right there in the editor pane of Xcode."

Phew. I think I'll tackle this tomorrow. Hopefully, I've finally gotten to the bottom of this tangled web of yarn.


Tuesday, January 1, 2013

iO6 6 needs a Xcode 5!

Well, I'm getting back into iPhone development *a little bit*. I've haven't been doing it for a while because of, well, other priorities, like locking down this new job I've got. But I did some development on the app a while back, and since then I've gotten an iPhone 4S (nice!). I strongly recommend for anyone Virgin Mobile's plan, which provides *unlimited data* for $30 bucks a month. The catch is you need to purchase the iPhone 4 or 4s model, with the 4s running at around $400 bucks as of late December.

Anyway, so my first obstacle is getting the program to run on the 4s. It appears (the device) on the organizer, but when I try to run the app, it gives me an error message: "Xcode cannot run using the selected device." "No provisioned iOS devices are available with a compatible iOS version. Connect an iOS device with a recent enough version of iOS to run your application or choose an iOS simulator as a destination".

Well, that's a surprisingly wordy yet somewhat helpful message. I suspect that it's only checking for previously provisioned devices, which at this point is my iPod touch, which I haven't updated for a while and therefore probably is running the old version of the iOS?

I'm not sure, but I think I need to provision the new device (4s) for development. Ah, actually, I missed this message on the Organaizer: "The version of iOS on “My Names’s iPod” does not match any of the versions of iOS supported for development with this installation of the iOS SDK. Please restore the device to a version of the OS listed below, or update to the latest version of the iOS SDK; which is available here."

Hmmm, I get conflicting advice from Google. I know there's a yellow dot next to the device name on Organizer - it should be green. Also, it's called "My Name's iPod Touch" which is bad since I'm connected to a 4s, yet its showing up, correctly, as an iPhone 4s as the device type.

Also, I'm pretty sure I never provisioned it for development or anything else yet.

So...what does it want? I'm thinking I need to provision this device, at least. If I right click on provisioning, and click help, I get a menu, which leads me to this:

Obtaining Certificates and Provisioning Profiles
 1. In the Devices organizer, select Provisioning Profiles in the Library section.
 2. Click Refresh.

What is a provisioning profile, exactly?
 "A provisioning profile is a collection of digital entities that uniquely ties developers and devices to an authorized iPhone Development Team and enables a device to be used for testing."

Great. Clear as mud.

"A Development Provisioning Profile must be installed on each device on which you wish to run your application code."

Well, whatever this frikkin' development provisioning profile is, it needs to be on the device. So I need to do this somehow.

"Each Development Provisioning Profile will contain a set of iPhone Development Certificates, Unique Device Identifiers and an App ID."

Brilliant. It needs an "iPhone Development Certificate" - another mysterious piece of digital gobbledy-gook which this russian doll of a process throws at us.

"Devices specified within the provisioning profile can be used for testing only by those individuals whose iPhone Development Certificates are included in the profile."

Ok, I will need a developer certificate - for inclusion in the developer provisioning profile - which must be installed on the device. Is there a PowerPoint that could make this clearer? With all their money, you think Apple could have better docs than this.

"A single device can contain multiple provisioning profiles."

Confusing. So, you have the profile. It has a collection of development certificates, device ids, and an app id. It's easer to think of the development certificates as "developer" certificates, since they are tied to individual.

Only one development provisioning profile per app, it looks like.

So for me, I just have my app, my developer/ment certificate, and my iPhone (I don't care about the iTouch just now).

Brilliant. more legalese from the help screen:

 "Obtain your code signing certificates and provisioning profiles to run apps in development on your development device."

Now I need a code signing certificate.  There seems to be some implicit assumption that I actually know what a code signing certificate is.  I'm assuming it is different than the developer certificate, I guess, and certainly different than the provisioning profile (which is for the developer/app/device combined, not just the developer).

"You must enter your development-team credentials so that Xcode can download the provisioning profiles containing your development certificate."

Umm...wait - I'm not on a development team. Is this something I need to contend with? And, where do I enter the credentials? Btw, what is a "development team" in this context and why do I need to know about it?

"If your development team does not have a development certificate for you, Xcode requests one."

Highly unlikely that would be the case, since I'm the only developer and have no idea who or what the "development team" is supposed to be.  Also, I resent some obscure scrap of data on some Apple server being referred as a "Development Team" as if it was some kind of, you know, actual flesh and blood entity.

"If your keychain does not contain your development certificate but your team has the certificate, Xcode downloads it from your team."

Again, the team. How does Xcode know which "team" to request it from, anyway?

"If your role in the development team is Member, inform the appropriate person in the team that there’s a pending certificate request."

Great. Now I'm supposed to know what my "role" is on this heretofore unknown "team". And what would this "appropriate person" do with this knowledge of my pending developer certificate request?


"If necessary, after the request is approved, follow the steps again to download your development certificate."

Some happy circumstance will have occurred where my cert is now created and available.

"If you are the team distributor, Xcode requests and downloads your team’s distribution certificate, in addition to downloading your development certificate."

A "team distribution certificate"? I can't take much more of this.

So, what is a certificate again? I think it's just a digital set of bits which can be encrypted by a public/private or private public key combination.

Appears to be a file with some info about the certificate's owner, and has the owner's public key. There's this whole thing about the certificate is signed by the CA (issuing authority) by creating a "hash" of the file using some kind of algorithm, e.g. MD5, then encrypting it using their private key.

Then, when your system receives the message, it checks if the certificate is from a a trusted issuer (which it keeps in a list) and if so, the system uses its public key (stored with the CA in the list) to decrypt the hash value (which means it came from them, if your system succeeds in the decrypt of the signature). Then, you run the decrypted signature (the contents of the cert) through the same hash algorithm, and it matches (the one that came with the message?), then you know it hasn't been tampered with. Whew.

So, I guess you get a certificate issued to you by Apple. A Developer certificate. Now, how does that help us get this app running? It's got to be connected the provisioning profile for your device and app, so your app can run.

So, that's what we're trying to accomplish.

From the dreaded "help" file:

"In the Devices organizer, select Provisioning Profiles in the Library section. Click Refresh."

Well, that option isn't there, but there's an intriguing one called "Add device to provisioning portal."

What might a provisioning portal be? Is this addition simply a way for apple to keep track of apps you make?

Anyway, let's see what happens.  Hmm... "No iOS Development Certificate Found" "No iOS development certificate was found. Would you like Xcode to request one for you?"

Well, I thought I had one, otherwise how could I have tested an app on my iPod touch? Or do they mean on my iPhone?

Well, I think I'm going to go ahead and let Xcode request it. It should already be in my keychain, but, I don't remember off the top of my head how to get at it. I'm just going to plunge ahead with this.

Xcode says "Submitting CSR", then "waiting csr approval". then "checking for pending csr". Now it says "No iOS Distribution Certificate Found" and "would you like Xcode to request one on your behalf?" Well, I mean, I had one of those too, but let's go with it. Xcode (again) says "Submitting CSR", and I missed the rest, but now it says: "Export Developer Profile?"

"Xcode added a signing certificate to your keychain. To ensure you can export code signing on other macs, you can export a developer profile that contains a backup of all your certificates and profiles. Would you like to export your developer profile now?"

Well, I don't have another Mac, but my wife and daughter each have one. Anyway, "Export" is the default, so let's hop on that train.

"Save as: DeveloperProfileExport and give a password. Hmm...well, now I have a valid "iOS Team Provisioning Profile" which shows up in my devices list, but IIRC, I had to create a profile specifically for this app."

Let's try to run the app.

Nope. Same problem.

Well, I selected a base sdk, and now my .app is showing up as red in the product folder. One wasn't selected at all before that. I think that this is maybe an issue with the SDK as the original message stated.

\Duh. I should've seen this earlier. It's right there in organizer, after the "develop" prompt:

 OS Installed on My Name's i whatever: 6.0.1 (10A523)
 Xcode Supported iOS Versions Latest 5.1 (9B176)

 Clearly, I need to download the latest xCode, from here (according the original message): https://developer.apple.com/membercenter/index.action.

Unhelpfully, just the generic developer's menu. This confirms I need to got 4.5: To develop for iOS 6 you need xcode 4.5. Xcode 4.4.1 supports only 5.1 iOS version (Stack Overflow). Wow. Huge down, 1.8 Gig. That's a wrap for today.