Question

Ive been searching for a solution for hours and my question is really simple. I have a local notification that fires and i want to load a new view to show the user when the notification has been fired and the user have clicked the "view" button. Is this possible and if so, how do i do it?

Thanks in advance :)

Was it helpful?

Solution

In your appDelegate put this code:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notif {
// show your view here!}

this method is called when your app receive the local notification and you can also use the "notif" object to store useful data when you create the notification.

If you have a view MyView and it's xib file (like MyView.xib where you set the main view as MyView class) you can do something like this to load it

In MyView.m add a class method to create a new view from a xib:

+ (id) newMyView
{
    UINib *nib = [UINib nibWithNibName:@"MyView" bundle:nil];
    NSArray *nibArray = [nib instantiateWithOwner:self options:nil];
    MyView *me = [nibArray objectAtIndex: 0];
    return me;
}

then in the local notification callback you can have something like:

MyView *view = [MyView newMyView];
[self.window addSubView:view];

Where window is the property you normally have in the app delegate template.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top