Brian Coleman

  • Home
  • ABOUT
  • SERVICES
  • PORTFOLIO
  • BLOG
  • Contact

Tutorial 59

Tutorial: Provision Your App to Run on a Device

One of the hardest things to figure out when starting iOS Development is how to work through the app provisioning process so you can test your provision your app to run on a real device. In order to deploy your app on a device you need to belong to the iOS Developer Program. Visit http://developer.apple.com/programs/ios to signup. It costs $99/year for the standard program. This also includes a host of development tools, resources, technical support and distribution of your application via the Apple App Store when you’re ready to release.

Registering Your Device

Before you do anything, you’ll need an iOS Device, this can be an iPhone, iPod Touch or iPad. To register your device within the Provisioning Portal you need to find out the unique identifier (UDID) for your device. Plug your device into your Mac and open up Xcode. Select Window > Organizer. Choose your device from the left and you’ll see the details on the right. Copy the 40 character “Identifier” to your clipboard.Screen Shot 2013-08-06 at 8.49.00 AMNext login to the iOS Developer Center https://developer.apple.com/devcenter/ios/index.action. You should see the screen below.Screen Shot 2013-08-06 at 8.41.13 AMSelect Devices to see the list of iOS Devices you have registered. To add a new one click the + plus button in the top right. Enter a name for your device, i.e. “Brian’s iPhone5”. Paste your device Identifier into the UDID space and click “Continue”.Screen Shot 2013-08-06 at 8.49.19 AMOnce added, you should now see your device in the list.Screen Shot 2013-08-06 at 8.49.35 AM

Setup Your Developer Certificate

To sign development versions of your iOS App you need to have a certificate installed on your Mac. To begin, select “All” from under the Certificates section on the left. Just like adding a new device select the + plus button from the top right. Then choose “iOS App Development” under the “Development” section and click “Continue”.
Screen Shot 2013-08-06 at 8.50.30 AM Next you’ll need to create a Certificate Signing Request (CSR). Follow the directions on the screen below.Screen Shot 2013-08-06 at 8.50.44 AMOpen “Keychain Access”, this can be found within your finder under “Applications > Utilities” or by searching “Keychain Access” in Spotlight. Then select “Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority”. Screen Shot 2013-08-06 at 8.52.04 AMEnter your Email Address, Name and select “Saved to disk”, then click “Continue”.Screen Shot 2013-08-06 at 8.52.57 AMSave the Signing Certificate Request to your desktop.Screen Shot 2013-08-06 at 8.53.37 AMNext, go back to the iOS Developer Center and click the “Choose File…” button and select the file you saved to your desktop.Screen Shot 2013-08-06 at 8.54.08 AMYour certificate is now generated, so click the “Download” button to save it to your computer. Screen Shot 2013-08-06 at 8.54.42 AMFind the file within your “Downloads” directory and double click it to install it into the Keychain Access. You should be able to click the arrow to the left of the certificate to see the private key under it. If you see this private key then you’ve installed the certificate correctly, if not try creating the certificate again.Screen Shot 2013-08-06 at 8.55.33 AM

Registering Your App

With every app you want to run on your device you need to register it within the iOS Developer Center. Click “App IDs” from the left menu under the “Identifiers” section. Just like we’ve done before select the + plus button from the top right to register a new App ID. Enter the Name of your app (this is not the name you’ll see in the App Store but for you to identify your app in your list of apps. Then enter a unique Bundle ID. This cannot be changed after this screen. Use the reverse-domain name style, i.e. com.rogers.ledbaseball, then click “Continue”.Screen Shot 2013-08-06 at 8.56.21 AMReview your application details and click “Submit” to finalize your App ID. Screen Shot 2013-08-06 at 8.57.37 AM

Create The Provisioning Profile

Now that we have our device registered, your certificate installed and our App ID setup it’s time to link them together in a Development Provisioning Profile. Click “Development” from under the “Provisioning Profiles” section on the left menu. Then like before click the + plus button in the top right to create a new provisioning profile. Click “iOS App Development” under “Development” and click “Continue”.Screen Shot 2013-08-06 at 9.02.23 AMSelect the App ID that you just created from the dropdown list and click “Continue”. Screen Shot 2013-08-06 at 9.02.40 AMSelect the certificate that you have installed on your Mac and click “Continue”. If you belong to a team of developers you’ll see their certificates listed. If you have an Individual account you’ll just see the one you setup. Screen Shot 2013-08-06 at 9.03.07 AMSelect the devices that you would like to run the app on. It doesn’t hurt to “Select All”. If you need to add a new device in the future you will need to add the device to the iOS Developer Center, then update the Provisioning Profile to include the new device. Screen Shot 2013-08-06 at 9.03.34 AMNext enter a name for your Provisioning Profile. I like to add “Dev” to the end if it’s a Development Provisioning Profile and “Store” to the end if it’s a Distribution Provisioning Profile because it’s easier to distinguish them later in Xcode. Then click “Generate”. Screen Shot 2013-08-06 at 9.03.54 AMClick “Download” to save the new Development Provisioning Profile to your computer. Screen Shot 2013-08-06 at 9.04.18 AMFind the file within your “Downloads” directory and double click it to install it into the Xcode Organizer. You should then see the Provisioning Profile in the list of apps. If the status is “Valid profile” then the profile is setup correctly, if not then try starting from the beginning again.Screen Shot 2013-08-06 at 9.05.18 AM

Configure Your App

If you have a valid provisioning profile the rest should work with no problem. Open up the app that you want to install on your device in Xcode. Select the Info.plist under the Supporting Files group within the project. Change the Bundle Identifier to the App ID that you setup in the iOS Developer Center.Screen Shot 2013-08-06 at 9.06.43 AMNext click on the Project Settings and select “Build Settings”. Scroll down to the “Code Signing” section. Select the “Code Signing Identity” to see the dropdown. This dropdown lists all of the Provisioning Profiles installed on your computer. Select the name of the profile you just setup. Screen Shot 2013-08-06 at 9.07.23 AMDo the same with all of the options under “Code Signing Identity”. Ensure they are all selected to the app provisioning profile. Screen Shot 2013-08-06 at 9.07.42 AMNext click the Target of the App and select “Build Settings”. Just like you did for the Project Settings change all of the “Code Signing Identity” to the correct app Provisioning Profile. Note: If you do not see the new Provisioning Profile in the list, restart XCode and it should show up. Screen Shot 2013-08-06 at 9.07.52 AMDo the same with all of the options under “Code Signing Identity”. Ensure they are all selected to the app provisioning profile. Screen Shot 2013-08-06 at 9.08.11 AMThat’s it, now in the top left of the toolbar in Xcode, select the scheme dropdown to choose your iOS Device that’s plugged-in. Build and run your app and it should show up on your device. Now you can test your app on a real device and show it off!

August 14, 2013 Tutorialsprovision, tutorial

Framework: RevMob

fullscreen_ios
Generating revenue from free applications is difficult. One great way to do this, aside from In App Purchases, is advertising. Advertising not only helps to generate revenue directly, but it can also serve as a constant reminder for your users that they should upgrade to a paid version of your app. The annoyance should be just enough to get them to want to pay for your game, without disrupting their experience and making them hate your app. Learn more about advertising strategies in a previous post Monetize Your App: Ad Supported.

The advertiser that I use in my apps is called RevMob. RevMob provides full screen ads that show something like “DOWNLOAD A FREE GAME”. The generic, seemingly exciting message is supposed to win the users’ curiosity enough for them to click on the ad. When they download the app that is shown, you get paid in the range of $1-$3. RevMob is a fairly new platform but is growing fast. It’s getting rave reviews by developers that it has the highest eCPM in the ad industry.

Setting up the RevMob in Your App

Follow the steps below to get started with RevMob:

  1. Visit www.revmob.com and sign up, don’t worry it’s FREE!
  2. Click the “Apps” tab then “Add app” and Select the Platform your app is on (iOS App).
  3. Enter the Name of your application.
  4. Make sure you copy the unique application ID (APP ID), you’re going to need it soon.
  5. Download the latest RevMob iOS SDK.
  6. Drag and drop the directory RevMobAds.framework inside one file group of your project on XCode (usually, “Frameworks”).
  7. Be sure to include the frameworks SystemConfiguration.framework, StoreKit.framework and AdSupport.framework that are not included by default. You can do that by clicking in the project root > Build Phases > Link Binary With Libraries > Click in the + button.
  8. Add the following code into your App Delegate.
    #import 
    - (void)applicationDidFinishLaunching:(UIApplication *)application 
    {
         [RevMobAds startSessionWithAppID:@"copy your RevMob App ID here"];
         //your code
    }
    

    The code above initializes the RevMob framework in your app. Be sure you add the correct APP ID for the application you setup on the RevMob website. Don’t put in the specific ad unit ID. The only ID you ever need to input is the APP ID, all of the banners will be called using the default methods that don’t require IDs.

  9. Insert a Full Screen ad within your application
    #import 
    - (void) displayAd {
         [[RevMobAds session] showFullscreen];
    }
    

    Above you’ll see the basic implementation for adding a Full Screen ad to your app. Be sure to include the RevMob framework at the top of the View Controller you are inserting the ad into. As another example see how to insert a Banner ad using the code below.

  10. Insert a Banner ad within your application
    #import 
    - (void) displayAd {
         [[RevMobAds session] showBanner];
    }
    

There are a couple of other ad units available such as Links, Buttons and Popups. You can read more information about integrating these in the RevMob SDK Documentation.

RevMob is one of the easiest SDKs to integrate into your app, so why not do it and start making money!

July 24, 2013 Frameworksframework, ios, tutorial

Tutorial: Reserve Your App Name Forever

So you have a great idea for an app but don’t have the time to complete it. You also have a great name for it, but how can you make sure that no one else will take it before you finish building your app? You should reserve it!

After creating your app and it is in the state “Prepare For Upload” or “Waiting For Upload”, you have 180 days (6 months) from your creation date in iTunes Connect to deliver a binary to Apple. If you do not deliver a binary before the 180-day deadline, your app is deleted from iTunes Connect. As a result of this deletion, your app name can be used by another developer and you cannot reuse the app name, SKU or bundle ID.

Steps to Reserving Your App Name Forever

  1. Log in to https://itunesconnect.apple.com
  2. Click Manage Your Apps
  3. Click Add New Application
  4. Complete the basic information, including the app name
  5. Upload temporary icons and screenshots (for iPhone 4 & iPhone 5)
  6. Change the app status to “Waiting for Upload”
  7. Create a very simple app and use the new bundle ID
  8. Submit the App to the App Store for Review (as you normally would)
  9. After the status has changed to “Waiting for Review” go into iTunes Connect
  10. Click Manage Your Apps > View Details > Binary Details
  11. Click Reject this Binary

This will set the status of your application to “Developer Rejected”. Since you have successfully submitted a binary and had a “Waiting for Review” status it can sit in that status forever, therefore your app name is parked forever! Apple considers it a “real” app since it was officially submitted. So now sit on your great app name until you’re ready to finish development.

July 18, 2013 Tutorialsapple, strategy, tutorial

Tutorial: Using Sub-Projects & Git Submodules to Create a Framework in iOS

If you manage a number of iOS applications that have a lot of the same features you may want to consider building a framework that can be used across all of them. There are a couple ways to do this, the most common would be to build a static library.

A great solution for creating a living framework that is worked on my multiple people is to create a sub-project. This means that we’ll store all of the re-useable code in the sub-project and embed it into the projects for all of our apps. This works especially well if you are using GitHub across all of your apps. I’ll show you how to add the sub-project as a submodule in Git allowing the sub-project to be modified as often as possible, then when you have to update your project with the most recent fixes you just pull the latest code from the sub-project and your master project is automatically updated.

Create the Static Library Project

To start we need to build the sub-project that will contain all the reusable code for our Framework. Create a new project from the “Cocoa Touch Static Library” template as shown in the screenshots below.

Static Library 1

Screen Shot 2013-07-05 at 9.08.05 AM

When saving your project, ensure that the “Create local git repository for this project” is checked, we’ll need this later when we want to automatically update our parent project with the latest code from the framework project using Git submodules.

Screen Shot 2013-07-05 at 9.08.39 AM

Next you’ll need to modify the copy files section within the target Build Phase so the library can be accessed by the project that includes it. Remove “${PRODUCT_NAME}” from the Subpath so only “include” remains.

Screen Shot 2013-07-05 at 9.09.22 AM

We’ll need to add all of the assets within the Framework into a Resource Bundle. Normally all of your assets are stored in the projects “main bundle” but for another project to access the assets using a library the best way is to store them in their own bundle. Resource Bundles should store all your images and nibs (XIB). Add a target to the library project using the template “Bundle”. From the “Build Settings” of your library project click the “Add Target” button.

Screen Shot 2013-07-05 at 9.09.48 AM

After the Resource Bundle is added we need to fix it’s architecture properties because by default Xcode adds it as a Mac OS X architecture. Navigate to the “Build Settings” of the Resource Bundle and change the “Base SDK” to the “Latest iOS” option.

Screen Shot 2013-07-05 at 9.10.50 AM

Below I’m adding a new UIViewController named “AdViewController”. This is going to be added to the Framework project and later we’ll access this class within the parent project. This will show you that you can add any class / SDK you wish to your Framework allowing you to access or extend it within your parent project. First we’ll create a new Objective-C class which will be a subclass of UIViewController.

Screen Shot 2013-07-05 at 9.11.15 AM

Screen Shot 2013-07-05 at 9.11.26 AM

Ensure that the new class is only being added to the “MyFramework” target, not the bundle. We’ll add the nib (XIB) to the Resource Bundle separately, we don’t want our .h or .m files in the Resource Bundle since it doesn’t know how to handle them when compiled.

Screen Shot 2013-07-05 at 9.11.37 AM

Navigate to the new “AdViewController.xib” file and check “MyFrameworkBundle” under the “Target Membership” on the right.

Screen Shot 2013-07-05 at 9.12.04 AM

Next we want to add our objects to the nib (XIB). Drag in a UILabel and change it’s text to “Hello Ad Framework”.

Screen Shot 2013-07-05 at 9.13.02 AM

Go to the “Build Phases” section and add the “AdViewController.xib” to the “Copy Bundle Resources” and in “MyFramework” add “AdViewController.h” to the Copy Files to ensure that these files will be accessible to the parent project.

Screen Shot 2013-07-05 at 9.13.34 AM

Screen Shot 2013-07-05 at 9.15.13 AM

Lastly commit all of the changes we’ve made to Git. Select “File > Source Control > Commit…”.

Screen Shot 2013-07-05 at 9.22.56 AM

That’s it our static library Framework is complete. Next let’s look how to incorporate this framework into an everyday project.

Create the Parent Project

You may already have an existing project to add your new Framework into but we’re going to assume that you’re starting a whole new project and the first thing you are going to do is add your Framework that contains all of the reusable classes you’ll use in your new app. Start out by creating a new “Single View Application”.

Screen Shot 2013-07-05 at 9.33.06 AM

Screen Shot 2013-07-05 at 9.33.21 AM

Same as with the static library, ensure that the “Create local git repository for this project” is checked, we need it to be able to add the Framework as a submodule.

Screen Shot 2013-07-05 at 9.33.29 AM

Let’s add the Framework as a Git submodule. Since we’re adding it as a submodule, anytime that the Framework has been updated all you’ll need to do it do a “git pull” from the submodule and your parent project and any other projects will be all be up to date without having to go into each one and cut and paste all the changes. So if you have 10 apps that all use your Framework and you fixed a bug with the Ad class or needed to update the latest third party SDK you use, make the change in your Framework, then open each of your apps, pull the latest Framework code, recompile and you’re ready to release your update to the App Store.

Navigate to the directory of your parent product using Terminal and type “git submodule add ../MyFramework” and press enter. This assumes that your Framework is stored locally. If you are using GitHub or BitBucket, point to the address of your repository.

Screen Shot 2013-07-05 at 9.34.38 AM

The Framework project will be added to a sub-directory under your parent project folder. Next, drag the Framework project file (.xcodeproj) into your parent product dock, as shown below.

Screen Shot 2013-07-05 at 9.35.57 AM

Screen Shot 2013-07-05 at 9.36.25 AM

Edit the parent project scheme to make it build the Framework’s project targets first. Edit the scheme and under the “Build” tab click the plus at the bottom and add the library target and library resources target. Select all of the Frameworks Targets and click “OK”.

Screen Shot 2013-07-05 at 9.36.35 AM

Screen Shot 2013-07-05 at 9.36.41 AM

Screen Shot 2013-07-05 at 9.36.45 AM

Link your Framework library file to your parent project. This is done very similar to how to include Frameworks like the “AudioToolbox.framework”. Select your parent project target, and click the + button under the “Linked Frameworks and Libraries” section, then choose the .a file associated with your Framework.

Screen Shot 2013-07-05 at 9.37.14 AM

To include the Resource Bundle, expand the “Products” folder from the Framework and drag the “MyFrameworkBundle.Bundle” into the “Copy Bundle Resources” section under the parent project target. Don’t mind that the colour of the two files under the products folder are red, they will look normal once they are compiled.

Screen Shot 2013-07-05 at 9.37.39 AM

Add the Framework targets into the “Target Dependencies” of the parent project so they will be compiled first before your parent product is compiled. If this isn’t done your project won’t know where to find the classes you are referencing.

Screen Shot 2013-07-05 at 9.38.14 AM

Screen Shot 2013-07-05 at 9.38.18 AM

Update the header search paths of the parent project. Go to “Build Settings” of the project and look for “User Header Search Paths”. Then set the target setting to “$(BUILT_PRODUCTS_DIR)” and select “Recursive”. This will be the location where your parent project will pickup the headers (.h) files of the Framework.

Screen Shot 2013-07-05 at 9.38.53 AM

Using The Framework

We’ve integrated the Framework into our parent project, now we’re ready to use the classes within it. This should be very straightforward because we can leverage the classes just like you would from within your project.

First import the header at the top of your implementation file.
[syntax_prettify linenums=””]
#import “AdViewController.h”
[/syntax_prettify]

Then add the following code to leverage the Framework Resources Bundle and present the AdViewController within the app.
[syntax_prettify linenums=””]
NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@”MyFrameworkResources” withExtension:@”bundle”]];
AdViewController *adView = [[AdViewController alloc] initWithNibName:@”AdViewController” bundle:bundle];
[self.view addSubview:adView.view];
[/syntax_prettify]

Once completed your code should look like this.

Screen Shot 2013-07-05 at 9.40.12 AM

When you run the sample project, the output should show the AdViewController.

Screen Shot 2013-07-05 at 9.40.37 AM

I hope this tutorial helped you to create your own Framework. Remember the advantage of embedding it as a sub-project allows you to view the code for the Framework while you’re using it and adding it as a Git submodule makes it really easy to keep your parent products up to date with the latest code for the Framework. Now go create your own Framework with all of the amazing classes you have created and want to reuse in every new app you create.

Grab the Source Code to this tutorial to help you debug any issues you had, but try to follow the tutorial yourself so you can learn all of the steps to ensure you know what each one does.

July 10, 2013 Tutorialsframework, ios, objective-c, tutorial

Tutorial: Run a Block of Code After a Delay

LED Baseball Pitch
For the longest time I’ve wanted to know how to pause the app or wait a certain amount of time before running a block of code. This is often useful for when you’re doing simple animations or if you need to wait before updating the UI. Take the example to the right, in the LED Baseball game I needed to find a way to animate the pitches from the mound to home plate. The LEDs images are in set spots, and for the effect of a pitch they need to blink on and off in sequence, sometimes at different speeds depending on the pitch.

The best way to implement this code block is to implement a category that can be reused in any of your projects.
The following code is credited to Duncan C.

The header file: (filename = NSObject+performBlockAfterDelay.h)

//
//  NSObject+performBlockAfterDelay.h
//
//  Copyright (c) 2012 WareTo. May be used by anyone, free of license, as 
//  long as this copyright notice remains.
//

@interface NSObject (performBlockAfterDelay)

- (void) performBlock: (dispatch_block_t) block
           afterDelay: (NSTimeInterval) delay;

@end

The .m file: (filename = NSObject+performBlockAfterDelay.m)

//
//  NSObject+performBlockAfterDelay.m
//  ChromaKey
//
//  Copyright (c) 2012 WareTo. May be used by anyone, free of license, as 
//  long as this copyright notice remains.
//

#import "NSObject+performBlockAfterDelay.h"

@implementation NSObject (performBlockAfterDelay)

- (void) performBlock: (dispatch_block_t) block
           afterDelay: (NSTimeInterval) delay;
{
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), 
                 block);
}
@end

To use it, just add the .m and .h files above to your project.
Then add a #import at the top of any .m file that needs this method:

#import "NSObject+performBlockAfterDelay.h"

Here’s a sample of the code in action for a fastball in LED Baseball.

[self performBlock:^{led1.hidden = NO;} afterDelay: .75];
[self performBlock:^{led1.hidden = YES;led2.hidden = NO;} afterDelay: .15];
[self performBlock:^{led2.hidden = YES;led3.hidden = NO;} afterDelay: .225];
[self performBlock:^{led3.hidden = YES;led4.hidden = NO;} afterDelay: .3];
[self performBlock:^{led4.hidden = YES;led7.hidden = NO;} afterDelay: .375];
[self performBlock:^{led7.hidden = YES;led8.hidden = NO;} afterDelay: .45];
[self performBlock:^{led8.hidden = YES;led9.hidden = NO;} afterDelay: .525];

By running a series of blocks in a row, each LED is shown, then hidden after a set delay.

I hope this code helps you as much as it did me, I’ll be using this category anytime I need to “pause”.

June 26, 2013 Tutorialsios, objective-c, tutorial
Page 10 of 12« First«...89101112»
Recent Posts
  • Classix for iPhone, iPad & Apple TV
  • Tutorial: How to test your app for IPv6 compatibility
  • Tutorial: Testing SSL using Charles Proxy on an iOS Device
  • Tutorial: 3D Touch – Quick Actions in Swift
  • tvOS Tutorial: Top Shelf in Swift
Featured Apps
Classix
Sportsnet
TAGS
tutorialswiftios8iosobjective-cvideogamesstrategynewsframeworkappsmonitizefacebookwatchappleios7toolstvosios9apiprovisionsocialtutorialsbooksdesignbookiapIPv6iTunes Connect
Search
TAGS
tutorialswiftios8iosobjective-cvideogamesstrategynewsframeworkappsmonitizefacebookwatchappleios7toolstvosios9apiprovisionsocialtutorialsbooksdesignbookiapIPv6iTunes Connect
ABOUT
Brian is a Lead iOS/tvOS Developer from Toronto with over 18 years of multifaceted experience including development, design, business analysis and project management.

FOLLOW ME
    
Email Subscription
Sign up for my newsletter to receive the latest news and tutorials posted.

Enter your email address:

2023 © Brian Coleman