IOS development-notification and message mechanisms, and ios development of message mechanisms
In most mobile applications, only one application can be active at any time, if some users are interested in other applications at the moment, the notification mechanism can be used to tell users what happened at this time. In iOS, the notification mechanism is also called the message mechanism. There are two types: Local notifications and remote notifications. The two types of notifications are consistent in iOS. You can use banners or pop-up reminders to notify users. clicking a notification can open the application, but the implementation principle is completely different. Today, let's take a look at how to implement these two mechanisms in iOS. The content of the notification center will be added later in the article to avoid confusion between the two concepts.
Notification
Local notifications are triggered by local applications. They are notifications Based on Time behaviors, such as scheduled alarms and to-do reminders, or if an application is not used for a period of time, it usually prompts the user to use this application and so on. It is a local notification. To create a local notification, follow these steps:
Create UILocalNotification.
Set the time when the notification is processed by fireDate.
Configure the notification content: Notification body, notification sound, icon number, and so on.
Configure the Custom Data parameter userInfo for notification transmission (this step is optional ).
Call Notification. You can use scheduleLocalNotification to schedule a notification as planned, or use presentLocalNotificationNow to call the notification immediately.
Next we will take a reminder that the user has not been using the program for a long time as an example to give a simple understanding of local notifications. This process does not involve too many interface operations, and all logic is in AppDelegate: if no notification is registered after the application is entered, you must first register the notification to request the user to allow the notification; once the registration method is called, the application will be called no matter whether the user chooses to allow the notification.
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
Proxy method. In this method, based on the user's choice: if the notification is allowed, the notification will be created according to the previous steps and executed after a certain period of time.