zhoudu
zhoudu

Reputation: 661

Is NSNotificationCenter related to Push Notifications?

I am trying to use NSNotificationCenter to register some notification observers in my iOS app. Is NSNotificationCenter related to Push Notifications? I think it is not, but I want to get some confirmation.

If I use NSNotificationCenter, do I need to do any additional thing?

In Certificates, Identifiers & Profiles in Apple developer member center, every app ID has an application service that is Push Notifications. The service is configured as enabled or disabled. I think that if I use NSNotificationCenter, I don't need to set that service enabled. Am I correct?

Upvotes: 2

Views: 1554

Answers (3)

onCompletion
onCompletion

Reputation: 6650

You are absolutely correct that NSNotificationCenter and Push Notifications are different thing. They are not related to each other. According to your explanation I think you will understand by an example correctly.

Example - Assume that I have two class like viewController and SecondViewController. Now I want to do some task on the viewController and that task will be performed by the response from the SecondViewController. In this case I will add an NSNotificationCenter method to the SecondViewController and in viewController I will add the observer method by following some @selector process.

 SecondViewController.m

[[NSNotificationCenter defaultCenter] postNotificationName:@"Address Found" object:self];


 viewController.m

- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedNotification:) name:@"Address Found" object:nil];
}

- (void)receivedNotification:(NSNotification *) notification {
if ([[notification name] isEqualToString:@"Address Found"]) {
    NSLog(@"Address Found for specific location");
} else if ([[notification name] isEqualToString:@"Not Found"]) {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"No Results Found" message:nil  delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alertView show];
}
}

For this NSNotificationCenter process there is no need to get Certificates, Identifiers & Profiles in Apple developer member centre.

On the other hand in case of Push Notifications process you need to get Certificates, Identifiers & Profiles in Apple developer member centre.

In case of Push Notifications you have to register with a server for the service response and message which you want to show on your device. For example you can use https://parse.com server for push related works done.

Thanks.

Hope this helped.

Upvotes: 1

rmaddy
rmaddy

Reputation: 318854

The two have nothing at all to do with each other.

NSNotificationCenter is internal to the running app and doesn't require a server or anything special setup in the provisioning profile or Info.plist.

Upvotes: 1

Ben Zotto
Ben Zotto

Reputation: 71048

Correct, they are different. NSNotificationCenter is a foundational component of the Cocoa frameworks, and is used for loosely-coupled messaging within an application. This system long predates Apple's push notification stuff, and you can use it freely.

Push notifications (local or remote) are handled through another mechanism entirely.

Upvotes: 1

Related Questions