Saturday, April 26, 2014

Find the user document directory in Simulator

One day, I want to backup my Sqlite database created inside the Simulator to my MacBook data directory and I was wondering if this is possible. Yes, it is possible. The files that was created in Simulator is physically located in your MacBook.

You can find the physical directory with the codes below:

  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];

Sample output:

  /Users/{your Macbook user name}/Library/Application Support/iPhone Simulator/7.1/Applications/{random number}/Documents

Monday, September 2, 2013

Submitting your app to iTunes Connect

The following article contains the information on how to submit your app to iTunes Connect. The most important for the first time submission in the app statuses and also how to resolve the test case done by the QA.

https://developer.apple.com/library/ios/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/10_ManagingYourApplications/ManagingYourApplications.html


Saturday, August 17, 2013

Resetting XCode settings/preferences

In case of any problem with the IDE and you can't find any solution to solve it and you don't want to waste time in re-installing XCode, you may run the following commands to delete the existing settings/preferences. The following codes was posted by someone in stackoverflow.com and it solves the Storyboard problem after I change the minimum supported iOS version from 5.1 to 4.0.

First, you need to close XCode IDE and then call out the Terminal:

rm -rf $HOME/Library/Application Support/Developer/Shared/Xcode
rm -rf $HOME/Library/Preferences/com.apple.dt.Xcode.*
rm -rf $HOME/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState
rm -rf $HOME/Library/Developer/Xcode

NOTE: the first command is for Xcode 5 only.

Thursday, August 1, 2013

Changing the UITableView background color when it was UITableViewStyleGrouped

What you need to do is to run the following code in the viewDidLoad even:

    self.tableView.backgroundColor = [UIColor BlackColor];
    self.tableView.backgroundView = nil;

Saturday, June 22, 2013

Play system sound in iOS

Playing the system sound in iOS is quite easy.

  • Create a project and add AudioToolbox.framework reference. 
  • To play the system sound, call AudioServicesPlaySystemSound(1104) where "1104" is the system sound ID.
  • For the complete list of system sound, you may refers to http://iphonedevwiki.net/index.php/AudioServices
You might found the following sample code (somewhere in the Internet) which load the "Tock" sound from the system resources and plays it. But, the following code might not play the sound because you should not call "dispose" function immediately after "play" function as the play function will take some time to execute the "playing" process. This results in the soundID has been disposed/reset before it has been played. The correct way is to call the dispose function when you are unloading the view or app.

     NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
    
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
    AudioServicesPlaySystemSound(soundID);

    AudioServicesDisposeSystemSoundID(soundID);

Sunday, June 16, 2013

Shorthand to initialize NSDictionary

We use to initialize the NSDictionary variable like this:


        NSDictionary* f =[NSDictionary dictionaryWithObjectsAndKeys:@"a", @"CODE", nil];

Instead, you can write your code like this:
   
        NSDictionary* f =@{@"CODE": @"a"};

Note: don't forget the the key & value position in the above codes located differently.

Wednesday, June 12, 2013

Section in UITableViewController

In table view, you may create sections to group the cells. To do this, just follow the settings below: