Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5 "Notification Center" API?

I'm talking about this: http://reviews.cnet.com/8301-19512_7-20120625-233/ios-5-notifications-a-deeper-look/

Those pulldown menus on iOS, I for the love of life cannot find any documentation on how to make a notification so that it shows an update while in another application. I don't know if I just am using the wrong terminology or what, but is it "NSNotificationCenter", and where is any documentation on it?

Thanks :)

like image 546
Ryan Copley Avatar asked Aug 30 '12 20:08

Ryan Copley


People also ask

What is NSNotificationCenter in iOS?

A notification dispatch mechanism that enables the broadcast of information to registered observers.

What is UNUserNotificationCenterDelegate?

UNUserNotificationCenterDelegate. An interface for processing incoming notifications and responding to notification actions. iOS 10.0+ iPadOS 10.0+ macOS 10.14+ Mac Catalyst 13.1+ tvOS 10.0+ watchOS 3.0+

How do I use Notification Center in Swift?

Note: You need to mark this function with @objc. That attribute makes your Swift function available in the Objective-C runtime. The NotificationCenter is part of the Objective-C runtime, so in order for it to call your function, you'll need to add that @objc attribute.


2 Answers

The numerical badge isn't the only property of a local notification. It can also display banners, and play sounds. These banners are subsequently added to notification center.

Here's an example:

- (void)addNotification {
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
 
    localNotification.fireDate = self.datePicker.date;
    localNotification.alertBody = self.messageField.text;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.applicationIconBadgeNumber = 1;
 
    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", @"Object 2", @"Key 2", nil];
    localNotification.userInfo = infoDict;
 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    [localNotification release];
}

And here's a tutorial: http://www.icodeblog.com/2010/07/29/iphone-programming-tutorial-local-notifications/

like image 196
Mick MacCallum Avatar answered Sep 30 '22 04:09

Mick MacCallum


refer to Local and Push Notification Programming Guide by apple:

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html%23//apple_ref/doc/uid/TP40008194-CH1-SW1

NSNotificationCenter is in fact not related and provides API to pass notifications internally in the app itself.

like image 42
aporat Avatar answered Sep 30 '22 02:09

aporat