2015-10-05 62 views
2

我想在我的iOS應用中使用NSNotificationCenter註冊一些通知觀察者。 NSNotificationCenter與推送通知相關嗎?我認爲不是,但我想得到一些確認。NSNotificationCenter與推送通知相關嗎?

如果我使用NSNotificationCenter,做我需要做任何額外的東西嗎?

在證書,標識符&概況蘋果顯影劑構件中心,每一個應用程序ID具有應用的服務,是推送通知。該服務被配置爲啓用或禁用。我認爲如果我使用NSNotificationCenter,我不需要啓用該服務。我對麼?

回答

1

正確,它們是不同的。 NSNotificationCenter是Cocoa框架的基礎組件,用於應用程序中的鬆耦合消息傳遞。這個系統早在蘋果推送通知的東西之前,你可以自由使用它。

推送通知(本地或遠程)通過另一個機制完全處理。

1

這兩者完全沒有任何關係。

NSNotificationCenter是內部運行的應用程序,並且不需要在供應配置文件或Info.plist的服務器或任何特殊設置。

1

你是絕對正確的,NSNotificationCenter和推送通知是不同的東西。他們不相互關聯。根據你的解釋,我認爲你會正確理解一個例子。

示例 - 假設我有兩個類等的viewController和SecondViewController。現在我想在viewController上執行一些任務,並且該任務將由來自SecondViewController的響應執行。在這種情況下,我將向SecondViewController添加一個NSNotificationCenter方法,並在viewController中通過遵循一些@selector進程來添加observer方法。

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]; 
} 
} 

對於這個NSNotificationCenter過程中沒有必要得到證書,標識&型材在蘋果開發會員中心。

另一方面,在推送通知過程中,您需要獲取Apple開發人員中心中的證書,標識&配置文件。

在您與您要顯示設備上的服務響應和消息的服務器註冊推送通知的情況下。例如,您可以使用https://parse.com服務器完成與推送相關的工作。

謝謝。

希望這有助於。