sha007
sha007

Reputation: 21

when clicking notification show the corresponding content in UITableViewCell?

I created an UITableView with CustomCells.when clicking a button in top of the view a local notification is created and the table view is updated.if the app is not in running state,then notification is shown in banner.When clicking the banner how to launch the corresponding updated UItableviewcell. Need help...

Upvotes: 1

Views: 126

Answers (3)

Mehul
Mehul

Reputation: 3198

@sha007, in your when app start, you have to write below Code,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
                                                                                         |UIRemoteNotificationTypeSound
                                                                                         |UIRemoteNotificationTypeAlert) categories:nil];

    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

    // Handle launching from a notification
    UILocalNotification *localNotif =
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotif) {
        NSLog(@"Handle launching-> Recieved Notification ");
        localNotif.applicationIconBadgeNumber = 0;// set here the value of badg

        dicttemp=[NSDictionary new];
        dicttemp=[NSDictionary dictionaryWithObject:[localNotif.userInfo valueForKey:@"sent"] forKey:@"sent"];

        //Here you can get dictionary from Local Notification(eg.localNotif.userInfo) & using it , Navigate to View Controller & then Reload Data ..
    }
    return YES;
}

& if you app is Foregroung Mode means its Running then Use Below Code..

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle the notificaton when the app is running
    NSLog(@"Handle the notificaton when the app is running -> Recieved Notification %@",notif);

    notif.applicationIconBadgeNumber = 0;// set here the value of badge

    dicttemp=[NSDictionary new];
    dicttemp=[NSDictionary dictionaryWithObject:[notif.userInfo valueForKey:@"sent"] forKey:@"sent"];

}

Upvotes: 0

Sarvjeet Singh
Sarvjeet Singh

Reputation: 1680

You can use application:didFinishLaunchingWithOptions method to receive UILocalNotification and to update your table view you can post NSNotification from this method.

Upvotes: 0

Peter K
Peter K

Reputation: 438

After clicking on banner if your application wasn't run, you will receive local notification in application:didFinishLaunchingWithOptions: in options dictionary, by key UIApplicationLaunchOptionsLocalNotificationKey. So you need to check this key on app start and show proper cells if local notification present.

Upvotes: 1

Related Questions