New Features of ios8: pushkit (required for voip developers)

Source: Internet
Author: User

New Features of ios8: pushkit (required for voip developers)

Question: What is pushkit?

Answer: ios8 Apple introduced the pushkit framework and a new push notification type, called voip push. this push method is designed to provide different capabilities from common apns push. Through this push method, the app can execute the code (before the notification is sent to the user ); the default action of a notification is different from that of an apns notification. No notification is displayed in the default action. Currently, the use of push kit is limited to voip push (based on the actual experience of the author, other types of push cannot work at the moment, and the sdk is also in evolution ).

Question: What Can pushkit do for us?

Answer: voippush in pushkit can help us improve the experience of voip applications, optimize the development and implementation of voip applications, and reduce the power consumption of voip applications, it requires us to re-plan and design our voip applications for a better experience (voip push can be said to be quasi-real-time, and the real-side latency is about 1 second ); apple aims to provide such a capability that allows us to discard the persistent connection scheme. That is to say, applications do not usually need to maintain connections with voip Servers. When a call or a call is received, complete the registration of the voip server. When the program is killed or the mobile phone is restarted, you can receive incoming calls from the other party to carry out the voip service normally. That is to say, we can use it to optimize the voip experience and increase the connection rate. when the conditions are ripe, we can completely discard the persistent connections in the background and go to the road that Apple planned for us.

For pushkit, apart from the official documentation of the apple framework: we can find a video to help understand pushkit: 712_sd_writing_energy_efficient_code_part_2. This video can also be downloaded from the official website of apple.

Limitations of pushkit:

Currently, pushkit only supports ios8. this feature is evolving, and its stability and performance on devices of different Ios s8, on the apple Developer Forum, there are also many people who have feedback. Based on experience, this function can be stabilized in the next major version (ios9.

If you need to support the pushkit function on devices before ios8, you need to make a lot of extra efforts. If you are interested, you can go to the relevant sections of the apple forum to learn more, some developers are far away in this regard:

 

After briefly introducing pushkit and what it can do and learning its limitations, you can continue to read the children's shoes that are also interested in pushkit (:) to avoid wasting your valuable time ).

Implementation of the voip function of pushkit:

1. Similar to apns push, pushkit voippush also needs to apply for a certificate. The process for applying for a voip push certificate is as follows:

 

2. use this certificate to export and load the certificate to the push server. You do not need to modify the server side. You only need to replace the certificate-related items (the specific process is similar to that of the previous apns certificate ); the interaction process between the server and the client is similar.

3. Client implementation:

Step 1: Add pushkit to the project;

Step 2: add support for voip, backgroundfetch, and remotenotifications to the backgroundmode in the project settings.

Step 3: To be safe, we recommend that you use the latest version of xcode and the latest sdk. We also recommend that you apply for a new mobile provision file for packaging.

Step 4: similar to the implementation process of the apns notification client, the process related to the voip push client is also similar: register the voip push notification to implement the pushkit-related proxy.

Paste the main code:

Call the following code after the application is started (didfinishlaunchwitexceptions of appdelegate) or after the root controller is initialized:
PKPushRegistry * pushRegistry = [[PKPushRegistry alloc] initWithQueue: dispatch_get_main_queue ()];
PushRegistry. delegate = self;
PushRegistry. desiredPushTypes = [NSSet setWithObject: PKPushTypeVoIP];

UIUserNotificationSettings * userpolicysetting = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories: nil];
[[UIApplication sharedApplication] registerUserNotificationSettings: userpolicysetting];
The above code registers voip push when the application starts;

Proxy for implementing voip push in the appdelegate or viewcontroller class:

@ Interface EPTabBarController: UITabBarController

-(Void) pushRegistry :( PKPushRegistry *) registry didUpdatePushCredentials :( PKPushCredentials *) credentials forType :( NSString *) type
{
If ([credentials. token length] = 0)
{
NSLog (@ voip token NULL );
Return;
}

ZeroPush * push = [[ZeroPush alloc] init];

// Push. apiKey = @ iosdev_1Z6JR3PKBWrAWbuHLbLQ;

Push. apiKey = @ iosprod_HZDimW5ssYsRQgaSaEoE;

// Iosprod_HZDimW5ssYsRQgaSaEoE

[Push registerDeviceToken: credentials. token channel: @ me];

}

The push server we connect to here is a service provided by zeropush. We will introduce this service later. The above proxy method is that the device obtains the voip token from the apple server, then pass the token to the application. We need to pass this token to the push server (similar to apns push, we also want to pass the apns token to the push server, but the two token can be obtained in different ways, callback to the application in different proxy methods, and the content of these two tokens is also different ).

After the push server obtains the user's voip token, it is triggered when another callback sends a message to the corresponding token device under the push server under normal conditions.

 

-(Void) pushRegistry :( PKPushRegistry *) registry didReceiveIncomingPushWithPayload :( PKPushPayload *) payload forType :( NSString *) type
{

NSLog (@ didReceiveIncomingPushWithPayload );
// Register the voip service at this time

// Write your voip related codes here

UIUserNotificationType theType = [UIApplication sharedApplication]. currentUserNotificationSettings. types;
If (theType = UIUserNotificationTypeNone)
{
UIUserNotificationSettings * userpolicysetting = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories: nil];
[[UIApplication sharedApplication] registerUserNotificationSettings: userpolicysetting];
}


UILocalNotification * backgroudMsg = [[UILocalNotification alloc] init];
BackgroudMsg. alertBody = NSInternationalString (@ You receive a new call, nil );
[[UIApplication sharedApplication] presentLocalNotificationNow: backgroudMsg];

}

The preceding callback Code only prints logs and triggers a local notification. This proxy method is triggered when a voip push notification is received. If everything works properly, this notification can still be triggered when the mobile phone is restarted, the application is recycled by the system, and the Manual kill program can be used to execute its own code (such as voip Registration) for a period of time ).

Here we will briefly design a business for your reference, mainly to make everyone intuitively aware of pushkit capabilities:

1. The long voip connection of the application is not retained, and the application is reconnected when a call is received or initiated;

2. When the call is sent to the voip server, if the peer is not online, a push notification is sent to the peer through the pushserver connected to the voip server;

3. When the application receives the voip push notification, the registration is completed quickly;

4. The caller successfully establishes a call by modifying the logic such as delayed operations (the voip server is more complex, and the caller is notified to the caller after the called connection is established.

 

 

I tried to send a mail to this mailbox on a certificate-related question and soon got a satisfactory answer. It was great!

Zero push provides a free trial service, which makes it very convenient for us to experience voip push;

Follow the prompts to register an account, create an application, upload a voip certificate, and obtain its apikey from the webpage (this key is used before the token is uploaded, in the proxy method above ).

 

Note that this project is written in the swift language. If your certificates and provision files are all previously applied and only used for the project created by the oc, this project may crash when it is running. The solution is to re-generate your certificate and provision file, use it in the project, and then re-package it, this problem can be solved.

 

Finally, you are welcome to discuss this topic in any form ~ I have noticed that there are very few Chinese documents or practice summaries on this topic in China. Most of them are in English. I hope to work with you to accumulate and make progress together ~

 

 

 

 

 

Related Article

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.