I don't have a physical Mac at the moment but I have a IPhone which I love! So how do I get my app running on my phone?
If you are like me this guide will help you get your Xamarin app to your IPhone (and your testers IPhones) without needing to buy a Mac!
To be able to run Xamarin apps legally on your IPhone you will need a physical Mac you'll need to buy an access to a Mac in the cloud.
I can't find information on it but the reason for you needing a Mac to build iOS code is either:
- Apple hasn't made 3rd parties it easy to use their build chain (XCode,etc) so they haven't invested in it
- Apple just doesn't allow it (Eula)
But the fact is that you will need a Mac (legal or not) to build your iOS code so it will run on your phone.
Me and Xamarin
I have been doing Xamarin development on and off since 2014 and dabbling in XCode/ objective-c for 1.5 years in 2011.
I have been doing some light teaching of Xamarin.Forms so I have the developing skills up to date (even though Xamarin is moving fast these days).
But in the last 2 years I have just been using the simulator and this year the LivePlayer in Visual Studio to develop the code.
Its been a long time since I connected a local Mac to Visual Studio to get the apps to my physical device.
The weekend project
And I didn't have a Mac to connect to! And I wasn't going to go out to buy one for this test (it might pay off in the long run though)
So what to do?
Mac in the cloud
Since I had previously (two years ago) bought access to a MacInCloud I decided to do that again since I knew (so I thought) I had some leftover prepaid credits.
What I came to realize was that I had 28 left of my 30 build minutes in the Pay-As-You-Go plan but since I had not logged on in the last 60 days it was void and I need to buy more.
While looking at the plans I saw something new, VSTS Build Agent
Connect MacInCloud to VSTS
So the next step was to connect MacInCloud to VSTS.
I managed to get this working by going over the "Getting Started with the MacinCloud VSTS Build Agent Plan" guide. Somebody really should update this since some steps were not straight forward in my case.
Now I when I build an iOS app it will use my MacInCloud to do it.
VSTS (Azure DevOps)
So what I first thought of was to open up VSTS and check if I could use the build tasks there to build and deploy a app.
So I added a Xamarin.iOS build step and got this (overload).
I tried to config and run this build and got some errors and warnings so I decided to quit that route and try something else and easier to start up (AppCenter).
I know VSTS is very powerful because I work with it every day. But I just wanted to get my mobile app pipeline up and running fast. I really didn't want to spend more time than needed setting this up.
And maybe it wasn't so hard in VSTS but I didn't want to find out. I'll try it out next time.
Last year I used AppCenter for building and distributing Android apps so I knew (hoped) it would be a little easier to setup.
I'm not going to show you how to setup an app in AppCenter and hook it up to your repository since they do a good job of guiding you through the process.
The build configuration
So for distributed test (Ad-Hoc) apps you will need to set up the build configuration as following in AppCenter.
And then upload your provisioning profile and certificate (that I'm going to show you how to create).
Provisioning profile and certificates (.p12)
This was the thing that took me the longest to do!
Everybody that has ever tried to get an app to the store or even to their testers know this. Articles like "Why I hate iOS as a developer" are a testament of that.
This is totally normal when dealing with Apple but its still easier if you have a Mac!
Again this all would have been a breeze if I had had a Mac. Because then I could probably have used use the new Automatic provisioning to do deal with this all for me.
By combining Automatic provisioning with a Pay-As-You-Go subscription (paired to Visual Studio) I could have had these files.
.CSR .mobileprovision .cer .p12/.pfx
Yes... Welcome to the jungle!
I tried to find out how to do this and just got lost fast.
I had allready found this article "Where do I get the code signing files I need" but it told me nothing about how to create the these files on Windows.
To create a certificate in you Apple development portal you need a .CSR file. There are millions of examples on how to do it on a Mac when doing iOS mobile developement. But I did´t see any (there probably are) mentioning that.
So I googled "creating a .csr file on windows" that led me to downloading the CSR creation program where I filled out the information about me and saved the .csr file.
Then I was able to choose "App Store and Hoc" type of certificate in the Apple portal and upload the .CSR and create the certificate!
Create a Ad Hoc provisioning profile
Next step is to create a provisioning profile for Ad Hoc. You will need a device setup under Devices where you need the UDID of your phone. You can get it by using e.g SuperUDIDI.
Download the provisioning profile (.mobileprovision). You'll need to upload it to AppCenter.
Download and install/extract .cer/.p12
Then you need to download the certificate you created. Double click it and install on your computer under your user and then export the private key to a .pfx file (.pfx == .p12).
Upload .mobileprovisionin and .pfx file to AppCenter
Just that. Upload these two files to AppCenter and you should be ready to go.
Queue a build in AppCenter
Now you should be able to build the app and get a notification email where you are can just download and install the new version of the app.
There where few other problems I had getting this up and running. They where mostly easily fixed.
"Project bundle identifier 'com.companyname.xx' does not match specified provisioning profile"
Open the Info.plist in Visual Studio and change the Bundle Identifier to the one you set in the Apple development portal.
You don't get an email after successful build?
I was so excited when the build got green! It said "App distributed". I waited for 20 minutes and no notification!
For some reason I (the only user anywhere) wasn't in the distribution group! So just make sure you are in the group set to get the updates.
So is it worth it or should I get a Mac?
I think I will look around and see if I can find a used older Mac Mini after this trial month. Lets see how many hours of build time I really need.
But at the moment I will be developing Xamarin.Forms using the simulator. And when I want/need to try the app on my IPhone I will just queue a build.
I'm sorry if some steps in here aren't as super detailed as I think they need to be.
The reason for it is that I thought setting this all up wouldn't be a problem. Specially after watching so many (obviously "hello world") CI/CD videos.
I just didn't start taking notes on what I was doing until after I was c.a 30% done.
If I ever need to do this again or help somebody else to do it I'll add more details to this article.
But I really hope somebody learned something reading this.
Will it pay off in the long run just to buy a Mac Mini? Yes I think so. It would take c.a 1 year to pay up the Mac Mini vs. MacInCloud, so I'm thinking of getting one eventually.