Earlier today, I had the opportunity to speak at 1DevDay Detroit 2012. This event, which I also spoke at last year, highlights the developer community in the metro Detroit area. There were a lot of tremendous speakers and the keynotes by Ted Neward and Chad Fowler were both great. This year, I spoke on Windows Azure Mobile Services. There seems to be more and more mobile development going on in Detroit so my talk, which focused on connecting iOS apps to Mobile Services was spot on. The audience was very engaged and had several follow up questions.
Slides and source code
I wanted to make sure everyone had access to the slides and source code from my session so you can access the slide deck here. As to the source code, things are slightly more complicated. Allowing you to download the source code is easy enough, however, you’ll still need to get a Windows Azure account, create a mobile service, set up the tables and the scripts. I’ll endeavor to help you do that here. First, you’ll need access to the source code. You can download the completed source code here. Once that is done, you’ll need to get a Windows Azure account and request access to mobile services. You can create a new Windows Azure account here. Remember that you will not be charged anything unless you manually remove the spending limit (which is set to ZERO by default). Once that is done, request access to Mobile Services and then set up a new mobile service.
Creating a Twitter app
Since our app requires Twitter authentication, you’ll need to create a new Twitter app. This requires a Twitter account (which you probably have). Log in and go to http://dev.twitter.com. Go to the top right and hover over your username until the drop down opens and you can go to My Applications. After that, click the Create a new application button. Fill out the form, using the link of your Mobile Service from the Dashboard tab in the portal (for example, in the session, the URL was https://devday.azure-mobile.net/) for the Website and Callback URL. With that done, you will need to click the Manage Keys button at the bottom of the portal when in your mobile service’s dashboard and copy the URL from before and the ApplicationKey into the appropriate spots in TodoService.m. Just look for the mobileServicesURL and appkey strings in that file.
Tables and scripts
Return to the portal and go to the Data tab. We need to create a couple tables and set their scripts. First, create a table named TodoItem and set the permissions on its operations to Only Authenticated Users. Next, go to the Scripts tab for the table and set the Insert script to be:
Next, we just need to create another table. Name this table ApnsToken and leave it’s permissions as is.
Handling certs and profiles
Unfortunately, this is the part that is truly complicated. You need to log into the Apple developer portal (which means you need an Apple iOS dev account) and create a new Application ID and then set it up for push notifications. You’ll then need a new Provisioning Profile which is tied to this App Id. After this is done, you’ll need to set your App’s Bundle Identifier to the same one set up with your App Id (for example, I created one named cmr.MobileServices.Quickstart to easily match up with the name of the Target. You may want to use XXX.MobileServices.Quickstart). This change can be made by selecting your project in the Project Navigator on the left side of Xcode and changing the Bundle Identifier. You’ll also need to change to change the Code Signing Identity in the Build Settings of the Target to your new provisioning profile. I’ve definitely glazed over details and left out screenshots here so if you need more assistance here, comment on the article or use the contact form to let me know.
Setting your push certificate
Before we can run our app, we need to do one more thing. In the Apple dev portal, download the certificate for your app’s push notifications. After downloading it, open the file which should cause the Keychain Access app to open. From here, you should be able to export that certificate as a p12 file. After that, go to the Push tab in the portal and under apple push notification settings, click the Upload button. Browse and find the p12 file and make sure DEB is selected for the Mode. Click the check mark in the bottom right and you should be good to proceed.
After all this you should be able to run the app. Keep in mind you’ll need to run the app on a device to get push notifications. Also, if the app is running on the device, you won’t see anything on the screen to signify a push. You should see something in the logs. Conversely if the app isn’t open on the device when a push is received, you will then see the notification at the top of your device’s screen. I’d like to thank everyone that attended and invite anyone with questions or issues to contact me.