Local Notification

There are 2 type of Notification in IOS.

Apple’s definition of the differences and when to use what,

Don’t confuse yourself with the 2 basically, Push Notification will require to set up the communication link to Apple’s Push Server and the way the Push Server works it have its own issue.

I have attached a guide that I used to set up APN previously.

Create your First Local Notification:

UIApplication *iosApp = [UIApplication sharedApplication];

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

NSTimeInterval timeZoneDiff = 8 * 60 * 60;

NSTimeInterval bug = 30 * 60;

NSDate *notifDate = [alertDate dateByAddingTimeInterval:[alertTime timeIntervalSince1970] + timeZoneDiff – bug];

localNotification.fireDate = notifDate;

localNotification.timeZone = [NSTimeZone systemTimeZone];

localNotification.alertBody = [NSString stringWithFormat:@”Alert : %@”, contentData];

localNotification.soundName = UILocalNotificationDefaultSoundName;

NSDictionary *dictionary = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@”%d”, uniqueId] forKey:@”id”];

localNotification.userInfo = dictionary;

[iosApp scheduleLocalNotification:localNotification];

Add the following method into your AppDelegate.m file. This method will be called when the user click on the View button when the notification pops up.

 – (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{

Now, the hard part, if you have a navigation controller in your application on clicking on the View Button most of the developers will just use the following

[(UINavigationController *) self.window.rootViewController pushViewController: <targetController> animated: TRUE];



By doing the above command, if we push another View A to the stack, the stack will look like the following:

-View A (new)
-View A

This will not be the result we want. So we need to clear all the view and make sure that we only have the HomeView (landing view) and the targetView.

In the applicationDidReceiveLocalNotification method,

We will declares the views we need:

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@”MainStoryboard” bundle:nil];

ViewA *vcA = (ViewA *)[storyboard instantiateViewControllerWithIdentifier:@”ViewA”];

HomeView *home = (HomeView *)[storyboard instantiateViewControllerWithIdentifier:@”home”];

UINavigationController *nav = (UINavigationController *) self.window.rootViewController;

nav.viewControllers = [NSArray arrayWithObjects:home,vcA, nil];

[(UINavigationController *)self.window.rootViewController popToViewController:vcA animated:TRUE];

As you can see from the above codes, we need to init the storyboard object as in the AppDelegate its still not created yet.

Then we declare the respective view, note you need to import the headers files.

Finally we add this views into the stack of the navigationController.

Instead of using push, we are using pop here. The reason for this is that push adds a new view to the stack, where as pop show something that is currently in the stacks.

I hope this help you guys in anyway possible and do drop me a comment if you need further clarification.

Xcode with Mac OS X 10.8 tip!

I have been on Snow Leopard for so long that when i moved on to the Mountain Lion (10.8), I felt really lost.

I used to be able to browser to also any folder in the system but now with this new mac its really making it a pain.

So for the benefit of the rest, to access the iPhone Simulator folder (this is where all the application you build on the Xcode are stored),

Go to Finder-> Go -> Go to Folder -> /Users/[your username]/Library/ -> Click GO

Look for the iPhone Simulator Folder -> Right Click It -> Select Make Alias and drag this to your desktop.

This should make access this folder much much easier.

SenTestingKit not loaded, Image not found

After moving from my old macbook pro (2009) to the new macbook pro (2012) on the Xcode Version (4.5.1), i tried running my app in the iphone simulator but was faced with this error.

dyld: Library not loaded: @rpath/SenTestingKit.framework/Versions/A/SenTestingKit

I am pretty sure that it was working perfectly in the old macbook pro, therefore i set out to google and see that alot of people actually hit this issue but there wasn’t any clear cut answer.

To solve this basically, expand your solution -> Frameworks -> Remove the SenTestingKit from your project. This should resolve the issue.

Note : Please remove reference not delete it.

Xcode’s Neat Feature: “SVN”

Been working with Xcode for more than a year now, I just wanted to highlight the following neat feature available in Xcode.

The ability to take snapshot and revert this back to the way it was before.

If you work with Virtual Machine, you will appreciate this function and understand how valuable it will be.

If not let me explain, take for example you made a mistake in your development deleting some really important codes away and you can’t undo. You will either find from a backup hdd or try to rewrite it again. But with snapshot you will not need to do either of the above (provide you dont lost the development due to a dead hdd).

Creating a Snapshot

Instruction to take a snapshot:

In Xcode, File -> Create Snapshot

This will save a snapshot of the current state in the Xcode’s Organizer.

Restore the Snapshot

Restore the snapshot by going to the following:

In Xcode, File -> Restore Snapshot

Managing the Snapshots

Anyone who have publish an app or work extensively will be aware of Xcode’s Organizer, but if you dont, no worries.

In Xcode, Window -> Organizer -> Select Projects (this is the third icon out of the five on the window)

On the right of the screen, you will see the project and you can delete or export the snapshot.

I am linking the official documentation from apple. Click ME


Ending this off, if you are not the only person working on the project, I recommend you go the commercial route which is the SCM. Eg. SVN or GitHub or TFS

But if you are just like me working on weekend project, do explore this snapshot features that comes along with the XCode.