In iOS most of time we need to pass our data to the different parts of the code in same
or another class. One of the easiest way to pass data is using local notification.
Follow the below steps to implement Local Notification in your app
1. First we have to setup class observer for notification
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
1. [notificationCenter addObserver:self selector:@selector(yourMethodName:)
name:@"yourNotificationName" object:nil];
2. Post Notification like below
1. NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
2. [notificationCenter postNotificationName:@"yourNotificationName"
object:yourObject];
3.Get passed object using the following line of code
1. -(void)yourMethodName::(NSNotification *)notification{
2. id passedObject = notification.object;
3. }
4. Remove observer while unloading or dealloc
1. [[NSNotificationCenter defaultCenter] removeObserver:self];
You can also pass even dictionary object to the notification.
If you have any further doubts, drop us an email at info@infigic.com and we’ll get back to you with the best possible solution. Infigic is a Mobile Application Development Company and we are always there to solve your queries.
or another class. One of the easiest way to pass data is using local notification.
Follow the below steps to implement Local Notification in your app
1. First we have to setup class observer for notification
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
1. [notificationCenter addObserver:self selector:@selector(yourMethodName:)
name:@"yourNotificationName" object:nil];
2. Post Notification like below
1. NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
2. [notificationCenter postNotificationName:@"yourNotificationName"
object:yourObject];
3.Get passed object using the following line of code
1. -(void)yourMethodName::(NSNotification *)notification{
2. id passedObject = notification.object;
3. }
4. Remove observer while unloading or dealloc
1. [[NSNotificationCenter defaultCenter] removeObserver:self];
You can also pass even dictionary object to the notification.
If you have any further doubts, drop us an email at info@infigic.com and we’ll get back to you with the best possible solution. Infigic is a Mobile Application Development Company and we are always there to solve your queries.
Comments
Post a Comment