Archive

Archive for the ‘iOS’ Category

Xcode cannot run using the selected device. No provisioned iOS device … iPhone 3G

There is no iOS 4.3 update for the iPhone 3G and iPod Touch 2G available.  If you have set the Deployment Target to 4.3 in your Xcode project settings you will get an error.

To run the app on your iPhone 3G you have to set the Deployment Target to 4.2.

Free Icons for iOS, Android & Windows Phone 7

Delete SQLite Database of iPhone/iPad Simulator App

You can find and delete the sqlite database file of your app here:

/Macintosh HD/Users/<username>/Library/Application Support/iPhone Simulator/<Simulator-Version>/Applications/<app-key>/Documents/

Check if view is visible

if (self.navigationController.visibleViewController == self) {}
Categories: CodeSnippets, Development, iOS

Exceptions and error handling in Objective-C

Compiler directives that are used for exception handling:

1. @try: block of code that can throw an exception.

2. @catch: define block of code to handle exception thrown by try block, this is usually an NSException object.

3. @finally: defines a block of code that executed whether an exception is thrown or not.

4. @throw: once your program detects an exception, it must propagate the exception to code that handles it. This code is called the exception handler. This entire process of propagating an exception is referred to as “throwing an exception”.

@try {
   NSLog(@"trying...");
   [object objectForKey:@"yeah"];
}
@catch (NSException * e) {
   NSLog(@"catching %@ reason %@", [e name], [e reason]);
}
@finally {
   NSLog(@"finally");
}

For more informations have a look at the documentation here.

Categories: Development, iOS, Objective-C

NSString Basics

Creating strings

NSString *myFirstString = @"foo";
NSString *mySecondString = [[NSString alloc] initWithFormat:
   @"%@%@%@i", myFirstString, @"bar", 1];

Comparing strings

NSString *myString = @"foo";
if([myString isEqualToString:@"foo"]) {
   NSLog (@"Strings are equal!");
}

Finding strings within strings

NSString *myString = @"foo";
NSString *searchForMe = @"Howdi";
NSRange range = [myString rangeOfString : searchForMe];
int location = range.location;
int length = range.length;

if (location != NSNotFound) {

   NSString *locationAndLength = [[NSString alloc] initWithFormat:
      @"Location: %i, length: %i", location, length];
   NSLog(@"I found something.");
   NSLog(locationAndLength);
}

Replacing strings within strings

NSString *myString = @"foo";
myString = [myString stringByReplacingOccurancesOfString:@"oo"
   withString:@"uu"];

Extracting substrings from strings

There are 3 methods that allow to extract substrings from a parent string:

  • -substringToIndex:
  • -substringWithRange:
  • -substringFromIndex: (which respectively take a substring from the beginning, middle, and end of a parent string)

The first method substringToIndex returns a new string which is composed of the characters from the beginning of the receiver string up to (but not including) the character at the specified index:

NSString *aString = @"Running out of ideas for strings.";
NSString *substring = [aString substringToIndex:7];
// result: @"Running"

The method substringFromIndex works in the same way, except now the substring starts at the specified index of the receiver (including the character at the index) and includes all the characters to the end of the receiver:

NSString *substring = [aString substringFromIndex:25];
// result: @"strings"

Finally, we have the method which lets us arbitrarily extract a substring from anywhere within the parent string substringWithRange. The argument to this method is an NSRange:

NSString *substring = [aString substringWithRange:NSMakeRange(15, 5)];
// result: @"ideas"

Here the range starts with the 15th character, “i”, and extends to include the next four characters, giving us a length of 5, “ideas”.

How to find class type of an object

February 1, 2011 1 comment
NSLog(@"Is of type: %@", [myObject class]);
NSLog(@"Is of type NSString?: %@", ([[myObject class] isMemberOfClass:
                                    [NSString class]])? @"Yes" : @"No");
NSLog(@"Is a kind of NSString: %@", ([[myObject classForCoder]
                  isSubclassOfClass:[NSString class]])? @"Yes" : @"No");

iPhone Video Screen Capture

There are lots of screen capture tools in the market. Two well-known tools are TechSmith’s Camtasia Studio and Jing. Both are available for Windows and Mac and can be used to capure everything you want on your screen. Here you can find a list of 27 useful screen capture tools.

For capturing the iPhone simulator there is also a special plugin which works with the built in iSight on a MacBook.

Categories: iOS

App Distribution

Requirements for a new app in iTunes Connect:

  • Your binary ready for upload with the Application Loader.
  • The price for the app.
  • The version number of the app you are adding. Numbering should follow typical software versioning conventions (for example, 1.0 or 1.0.1 or 1.1).
  • A description of the app you are adding, detailing features and functionality. Descriptions cannot be longer than 4000 bytes.
  • A Primary Category that best describes the app you are adding.
  • A Secondary Category (optional).
  • One or more keywords that describe the app you are adding. When users search the App Store, the terms they enter are matched with keywords to return more accurate results. Separate multiple keywords with commas. Keywords cannot be edited once your binary is in review and cannot be longer than 100 bytes.
  • Copyright informations with the name of the person or entity that owns the exclusive rights to the app, preceded by the year the rights were obtained (for example, “2008 Acme Inc.”).
  • A Contact Email Address where Apple can contact you if there are problems with your app. This address will not be seen by customers.
  • A Support URL that provides support for the app you are adding. This will be visible to customers on the App Store.
  • An App URL with information about the app you are adding. If provided, this will be visible to customers on the App Store. (optional)
  • Large version of the app icon that will be used on the App Store. It must be at least 72 DPI and a minimum of 512×512 pixels (it cannot be scaled up). It must be flat artwork without rounded corners.
  • At least one screenshot. iPhone and iPod touch Screenshots must be .jpeg, .jpg, .tif, .tiff, or .png file that is 960×640, 960×600, 640×960, 640×920, 480×320, 480×300, 320×480, or 320×460 pixes, at least 72 DPI, and in the RGB color space. iPad Screenshots must be .jpeg, .jpg, .tif, .tiff, or .png file that is 1024×768, 1024×748, 768×1024, or 768×1004 pixes, at least 72 DPI, and in the RGB color space.

Now you are ready to upload your app with the Application Loader and the approval process will start automatically.

Check the App Store Review Guidlines to ensure that your app will be announced! You can find them here.

If some functions of your app are only visible or available after a login you have to provide a demo access! You can provide the login data via the optional Review Notes field in iTunes Connect.

The easiest way to submit your app to the app store is to use the “Build and Archive” build option and after that to use the “Submit Application to iTunes Connect….”! in the organizer.

Categories: Distribution, iOS

Closing an app with iOS 4.0

  • press the home button
  • double tap the home button
  • hold the app icon
  • close the app by clicking the minus button
Categories: iOS