Push notifications for iOS (local push and remote push)

Source: Internet
Author: User
Tags notification center

Push notifications and nsnotification are different:

Nsnotification: I can't see it.

Push notifications: Yes, you can see them.

Two push notifications are available in iOS

Local push notifications: (local Notification): Notifications from the mobile app itself, such as: alarm

Remote push notifications: (remote Notification) notifications sent from the server

What push notifications do: Let apps that aren't running in the foreground tell the user what's going on inside the app. For example, we were talking, and suddenly there was a black translucent banner on the screen (a message sent by a QQ friend). This is a push notification.

The rendering effect of push notifications:

1: Display a banner at the top of the screen (show details)

2: Pop up a uialertview in the middle of the screen (show specific content)

3: You can also play the sound effect while rendering push notifications (reminder)

4: Screen lock screen is also rendered (display specific content)

5: While rendering push notifications, you can also update the top right corner of the app icon (indicating the number of new content)

6: Push notifications received by the user are displayed in the Notification Center (the window that the finger pulls down from the top of the screen) (shows the specific content)

Details of the use of push notifications:

StartFragment

1: When a push notification is issued, the push notification will not be rendered if the current program is running in the foreground

2: When you click the push notification, the app that sent the push notification is automatically opened by default

3: Push notifications can be sent as scheduled, regardless of whether the app is open or closed

What is a local push notification:

As the name implies, there is no need for networking to send a push notification (do not need server support)

Usage scenarios for local push notifications:

Often used to regularly remind users to do some tasks, such as: Clean up garbage, bookkeeping, shopping, buy clothes, watching movies

How to issue a local push notification:

Steps:

1: Registration notification type (after IOS8)

2: Create a local push notification object

3: Customizing a notification

#import "ViewController.h"

@interface viewcontroller ()

@end

@implementation Viewcontroller

-(void) viewdidload {

[Super viewdidload];

//1:ios8 need to register the notification type , including which ( sound , icon text ,) information ,

/*

Uiusernotificationtypenone = 0

Uiusernotificationtypebadge = 1 << 0 contains the icon text ( the number in the upper-left corner ) 0001

Uiusernotificationtypesound = 1 << 1 sound ----------------->0010

Uiusernotificationtypealert = 1 << 2 theme content --------------->0100

currently : 0111, This value is numeric , below | | | The content in between is equal to the value

*/

//|: displacement operator

uiusernotificationsettings *seting=[uiusernotificationsettings settingsfortypes:  Uiusernotificationtypebadge | Uiusernotificationtypesound | uiusernotificationtypealert categories:nil];

[[uiapplication sharedapplication]registerusernotificationsettings: seting];

}

-(void) Touchesbegan: (nsset *) touches withevent: (uievent *) event{

// Tell it to have a local notification

///2: Create a local push notification object

uilocalnotification*local=[[uilocalnotification alloc]init];

/*

timer-based scheduling specific time to send notifications

@property (nonatomic,copy) nsdate *firedate; Trigger Time

@property (nonatomic,copy) Nstimezone *timezone; Time Zone

@property (nonatomic) Nscalendarunit repeatinterval; Repeat Interval

@property (nonatomic,copy) Nscalendar *repeatcalendar; Repeat Interval

@property (nonatomic,copy) clregion *region Ns_available_ios (8_0); Area

@property (nonatomic,assign) BOOL regiontriggersonce Ns_available_ios (8_0); determines a BOOL value for a zone

Alerts Warning

@property (nonatomic,copy) NSString *alertbody; Topics for Reminders

@property (nonatomic) BOOL hasaction; No does not show slide unlock button instead of display

@property (nonatomic,copy) NSString *alertaction; Slide the unlocked text

@property (nonatomic,copy) NSString *alertlaunchimage; Start The program's startup image When you click the notification banner

@property (nonatomic,copy) nsstring *alerttitle tip title Text ns_available_ios (8_2);

Sound

@property (nonatomic,copy) NSString *soundname; accompanied by the sound , the default is uilocalnotificationdefaultsoundname

Badge

@property (nonatomic) Nsinteger applicationiconbadgenumber; the number in the upper right corner of the icon

User Info

@property (nonatomic,copy) nsdictionary *userinfo; user-specified carrying parameters , converted to key-value pairs in the dictionary

@property (nonatomic, copy) NSString *category Ns_available_ios (8_0); category

*/

// Assign values to these attributes to allow notifications to have specific content

Local. alertbody=@ " Goddess : is it ?" ;

// specific time to show it ( from now on 5 seconds later )

Local. firedate=[nsdate datewithtimeintervalsincenow:5];

// Slide the unlocked text ( a small line below the push notification message )

Local. alertaction =@ " approx ";

// have voice to sound , no sound with default

Local. soundname=@ "Uilocalnotificationdefaultsoundname";

// set icon upper right corner number

Local. Applicationiconbadgenumber=+;

// user Information

Local. userInfo=@{@ "name":@ " goddess "@ "Content":@ " no ", @ "Time ":@ "20180101"};

//3: Customizing a notification

[[uiapplication sharedapplication]schedulelocalnotification: local];

}

@end

What is remote push?

Remote: Notification to the client from the remote server (requires networking)

Send a notification from the server, after receiving the notification to do and local notification of similar things, this notice is only from a remote server sent over,

The remote push notification to be made is a remote push service, also known as APNs (Apple push Notification services: MAC push notification Service), and Apple provides this service to us for remote push service.

Why use Apple's server?--> We all know that the program is alive when it can interact with its own server (the program can live to execute code), but as long as the user closes the app, it will not be able to communicate with the app's server, The latest data content cannot be obtained from the server. When we use QQ, even if not logged QQ can receive information, this is the use of remote push notification to do. No matter landing or not landing QQ, can be received, but the premise is to be networked.

Remote Push notification usage Note: All Apple devices in the networked state, will be connected with Apple's device to establish a long connection (as long as the connection, want to send data, can be sent at any time, always keep connected), Apple has a server cluster, with all Apple devices to establish a long connection

The role of long connections: Time calibration, system upgrade, Find My iphone,

The benefits of long connections: data is kept up-to-date, the transfer is fast (previous connections need to be held several times according to the protocol, Apple is directly connected).

Enjoy Apple's APNs service as long as you keep a long connection with the evaluation device, for example:

For example, I agentlxj now have an iphone, mobile phone has a lot of applications such as QQ,QQ has a server, my phone is now connected and QQ software to open, MO Mo Server can interact with me, I want to pass the message, or I received the message, Mo Mo Server amount to tell me directly. If I quit QQ (not uninstall), but my phone is still in the Internet, QQ can not give me push message, at this time the service will be Apple, as long as my mobile phone in the networked state (Apple is established is a long connection), Apple to send me the message if you know which device, How do you tell which device it is? Our phone has its own unique identity, with the device's unique identity to know which device to push to, but there is a problem, my phone can not only QQ such a software, such as also, Mo Mo and other software, so Apple also need to know the software Bundleid ( application's unique identity), with the device and program's unique identity, you know which application to push to which device. Now there's another problem, and Apple doesn't know what to push. Here is a concept: the message body (source: Who sent it to me, such as: Xiaoxifu. Message content: For example to me said is: Eat?), Apple does not know this message body, but this news QQ know, my xiaoxifu hair of this message body first to QQ server (tell QQ I want to send him a message), QQ server first look at the accepted people (i) online no, online directly sent past is over, If I am not online, then the Apple server can send, so to the Apple server, but to the Apple server is required 1: Pay $99 to become a developer to enjoy this service. 2: Message body  3 target Devicetoken, QQ server is not eligible to save each device's unique identity and Bundleid, Apple thought of a way, called Devicetoken (APPID (Application location identification) and UUID (device unique identification). Tell me these three apples can help us do things, How to parse Devicetoken Apple knows, so QQ has a database, once someone registers or is logged in (because the phone and the Apple is a long connection, once the login or registration will send the device ID and software ID, and the Apple server to obtain Devicetoken) QQ database will save the user's information, such as ID, name, gender, Devicetoken (if my Devicetoken by Apple encryption generated is APENTLXJ) and so on information, devicetoken in each landing time to save, because the user may change the phone, Once the mobile phone user's UUID changed, then need to regenerate a devicetoken, and then save the latest devicetoken to the server, Xiaoxifu I send a message when I go to find apples, to see if you are in line with the above three (paid, there is a message, the target of the DEVICETOKEN:APENTLXJ)), a look in accordance with the sent to me

Add: How many apps on a mobile phone have the number of Devicetoken,

If QQ is pushed to more than one device at the same time, for example, my QQ mobile phone on the board, the ipad is also on, this time depends on the QQ server sent to Apple's APNs Devicetoken, send one to a device, two Devicetoken, sent to two units.

If I change the time of the android landing Mo Mo, this is Google to push notifications, Google also has a big push server to engage.

Push notifications for iOS (local push and remote push)

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.