iOS notification hubs

Source: Internet
Author: User

iOS Notification hubs

It is a message broadcast mechanism inside an iOS program that enables communication between objects without referential relationships. Notification Center He is based on the observer pattern, which can only communicate within the program, not across application processes.

When the notification center receives the message, it sends the message to the Subscriber based on the settings, where subscribers can have multiple

Notification Center principle

after reading you should understand what the notification center did, Next we'll take a look at the notification center.

There are 2 classes that must be understood first:

// This class is used to pass a carrier that transmits information during a send notification. nsnotification // This is the soul of the notification hub in iOS, which implements the observer pattern and provides the developer with an interface such as registering and deleting the observer, and we can use a singleton to get an example of it . Nsnotificationcenter
Code implementation Register a notification observer
//register a notification observerNsnotificationcenter.defaultcenter (). Addobserver (Self, selector: #selector (Viewcontroller.refreshtext (_:)), Name: Krefreshtextnotification,Object: NIL) SELF: Observer selector: How to receive notification execution name: notification nameObject: //methods to be executed upon receipt of notificationfunc Refreshtext (notification:nsnotification) {ifNotification.Object  isNserror {return} textfield.text= String (notification.Object!)}
Send a notification to the viewer
Object " fffffff " , Userinfo:nil) krefreshtextnotification: Notification name object: Parameter userInfo: Other parameters
Removing observers
deinit {        object: nil)    }

In addition to this way, the system has a

Object inch }

But in the project is not much use, so it is not detailed introduction, in fact, the use of similar, but when using the need to pay attention to circular reference problems, such as you in the internal with self, the self corresponding class object will not be released

Removing the observer needs to be aware that nsnotificationcenter.defaultcenter () cannot be used. Removeobserver (self, name:krefreshtextnotification, Object:nil) , need to use nsnotificationcenter. Defaultcenter (). REMOVEOBSERVER (Observer)

System Notifications

In addition to the custom notification name, the system actually has a part of the well-known

Uidevice Notice
Uideviceorientationdidchangenotification    //uidevicebatterystatedidchangenotification   //uidevicebatteryleveldidchangenotification   //  //  proximity sensors (e.g., the device is close to the user's face)
Keyboard notifications
//////////// Keyboard position size changed

When the system issues a keyboard notification, it comes with additional keyboard-related information (a dictionary), and the dictionary common key is as follows:

// //// Keyboard animation execution Rhythm (speed)     
App Notifications
//These notifications was sent out after the equivalent delegate message is called@available (IOS4.0, *) PublicLet uiapplicationdidenterbackgroundnotification:string@available (IOS4.0, *) PublicLet uiapplicationwillenterforegroundnotification:string PublicLet uiapplicationdidfinishlaunchingnotification:string PublicLet uiapplicationdidbecomeactivenotification:string PublicLet uiapplicationwillresignactivenotification:string PublicLet uiapplicationdidreceivememorywarningnotification:string PublicLet uiapplicationwillterminatenotification:string PublicLet uiapplicationsignificanttimechangenotification:string PublicLet uiapplicationwillchangestatusbarorientationnotification:string//UserInfo contains nsnumber with new orientation PublicLet uiapplicationdidchangestatusbarorientationnotification:string//UserInfo contains nsnumber with old orientation PublicLet uiapplicationstatusbarorientationuserinfokey:string//UserInfo Dictionary key for status bar orientation PublicLet uiapplicationwillchangestatusbarframenotification:string//UserInfo contains nsvalue with new frame PublicLet uiapplicationdidchangestatusbarframenotification:string//UserInfo contains nsvalue with old frame PublicLet uiapplicationstatusbarframeuserinfokey:string//UserInfo Dictionary key for status bar frame@available (IOS7.0, *) PublicLet uiapplicationbackgroundrefreshstatusdidchangenotification:string@available (IOS3.0, *) PublicLet uiapplicationlaunchoptionsurlkey:string//UserInfo contains nsurl with launch URL@available (IOS3.0, *) PublicLet uiapplicationlaunchoptionssourceapplicationkey:string//UserInfo contains nsstring with launch app bundle ID@available (IOS3.0, *) PublicLet uiapplicationlaunchoptionsremotenotificationkey:string//UserInfo contains nsdictionary with payload@available (IOS4.0, *) PublicLet uiapplicationlaunchoptionslocalnotificationkey:string//UserInfo contains a uilocalnotification@available (IOS3.2, *) PublicLet uiapplicationlaunchoptionsannotationkey:string//UserInfo contains object with the annotation property list@available (IOS4.0, *) PublicLet uiapplicationprotecteddatawillbecomeunavailable:string@available (IOS4.0, *) PublicLet uiapplicationprotecteddatadidbecomeavailable:string@available (IOS4.0, *) PublicLet uiapplicationlaunchoptionslocationkey:string//app is launched in response to a corelocation event.@available (IOS5.0, *) PublicLet uiapplicationlaunchoptionsnewsstanddownloadskey:string//UserInfo contains an nsarray of Nkassetdownload identifiers@available (IOS7.0, *) PublicLet uiapplicationlaunchoptionsbluetoothcentralskey:string//UserInfo contains an nsarray of Cbcentralmanager restore identifiers@available (IOS7.0, *) PublicLet uiapplicationlaunchoptionsbluetoothperipheralskey:string//UserInfo contains an nsarray of Cbperipheralmanager restore identifiers@available (IOS9.0, *) PublicLet uiapplicationlaunchoptionsshortcutitemkey:string//UserInfo contains the Uiapplicationshortcutitem used to launch the app.//Key in Options dict passed to Application:[will | Did]finishlaunchingwithoptions and info for UIAPPLICATIONDIDFINISHL Aunchingnotification@available (IOS8.0, *) PublicLet uiapplicationlaunchoptionsuseractivitydictionarykey:string//sub-dictionary present in Launch options if user activity is present@available (IOS8.0, *) PublicLet uiapplicationlaunchoptionsuseractivitytypekey:string//Key in user activity dictionary for the activity type@available (IOS8.0, *) PublicLet uiapplicationopensettingsurlstring:string//Keys for application:openURL:options:@available (IOS9.0, *) PublicLet uiapplicationopenurloptionssourceapplicationkey:string//value is an nsstring containing the bundle ID of the originating application@available (IOS9.0, *) PublicLet uiapplicationopenurloptionsannotationkey:string//value is a property-list typed object corresponding to what the originating application passed in Uidocumentinteracti Oncontroller ' s annotation property@available (IOS9.0, *) PublicLet uiapplicationopenurloptionsopeninplacekey:string//value is a bool NSNumber, set to YES if the file needs to being copied before use//Content size Category Constants@available (IOS7.0, *) PublicLet uicontentsizecategoryextrasmall:string@available (IOS7.0, *) PublicLet uicontentsizecategorysmall:string@available (IOS7.0, *) PublicLet uicontentsizecategorymedium:string@available (IOS7.0, *) PublicLet uicontentsizecategorylarge:string@available (IOS7.0, *) PublicLet uicontentsizecategoryextralarge:string@available (IOS7.0, *) PublicLet uicontentsizecategoryextraextralarge:string@available (IOS7.0, *) PublicLet uicontentsizecategoryextraextraextralarge:string//Accessibility Sizes@available (IOS7.0, *) PublicLet uicontentsizecategoryaccessibilitymedium:string@available (IOS7.0, *) PublicLet uicontentsizecategoryaccessibilitylarge:string@available (IOS7.0, *) PublicLet uicontentsizecategoryaccessibilityextralarge:string@available (IOS7.0, *) PublicLet uicontentsizecategoryaccessibilityextraextralarge:string@available (IOS7.0, *) PublicLet uicontentsizecategoryaccessibilityextraextraextralarge:string//Notification was emitted when the user had changed the preferredcontentsizecategory for the system@available (IOS7.0, *) PublicLet uicontentsizecategorydidchangenotification:string//UserInfo dictionary would contain new value for Uicontentsizecategorynewvaluekey@available (IOS7.0, *) PublicLet uicontentsizecategorynewvaluekey:string//NSString Instance with new content size category in UserInfo//This notification was posted after the user takes a screenshot (for example by pressing both the home and lock screen Buttons)@available (IOS7.0, *) PublicLet uiapplicationuserdidtakescreenshotnotification:string//Extension Point Identifier constants@available (IOS8.0, *) PublicLet uiapplicationkeyboardextensionpointidentifier:string

iOS notification hubs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.