iOS8 new features: Pushkit Combat Summary (VoIP developer must read)

Source: Internet
Author: User

What is Question:pushkit?

Answer:ios8 Apple introduced a new framework called Pushkit and a new push notification type, called VoIP push. The push method is designed to provide the ability to differentiate from normal APNs push. This push allows the app to execute the code (before it pops up to the user), and the default behavior of the notification differs from the APNS notification, which does not pop up notifications in its default behavior. At present, the use of push kit is also limited to VoIP push (according to the author's actual experience, other types of push temporarily can not work, the SDK is also in the evolution).

What can question:pushkit do for us?

The Voippush in Answer:pushkit can help us improve the experience of VoIP applications, optimize the development of VoIP applications, reduce the power consumption of VoIP applications, and require us to re-plan and design our VoIP applications for a better experience (VoIP Push can be said to be quasi-real-time, real-side delay of about 1 seconds or so; Apple's aim is to provide the ability to abandon the scenario of a long connection in the background, that is, the application usually does not maintain the connection with the VoIP server, when the call or receive the call, the completion of the VoIP server registration When the program is killed or the phone restarts, you can receive calls from each other, the normal development of VoIP business. That is, we can now use it to optimize the VoIP experience, increase the connection rate, and when the conditions are ripe we can completely abandon the long connections in the background and go to Apple for our planned path.

For Pushkit, in addition to the Apple Framework Official document: https://developer.apple.com/library/prerelease/ios/documentation/ Beyond the networkinginternet/reference/pushkit_framework/index.html#protocols, there is nothing that can be found to help understand Pushkit WWDC video: 712_sd_ Writing_energy_efficient_code_part_2. This video can also be downloaded from the Apple website.

Limitations of Pushkit:

At the moment, Pushkit only supports iOS8, and the functionality is evolving, stability and performance on different iOS8 devices may vary, and there are many feedback questions on the Apple Developer Forum, which, based on experience, can be expected to stabilize on the next big version (that is, iOS9).

If you need to support the Pushkit feature on a device prior to iOS8, there will be a lot of extra effort on the part of the developer, not here, interested students can go to the Apple Forum to understand the relevant sections, some developers walk in this area is far:

Search for Pushkit keywords in the links below to find relevant content: Https://devforums.apple.com/community/ios/connected/push


After a brief introduction of Pushkit and what it can do and understand its limitations, children's shoes that are of interest to Pushkit can continue to look down (:) in order to avoid wasting everyone's valuable time.

The implementation of Pushkit VoIP features:

1. Similar to APNs push, Pushkit Voippush also need to apply for a certificate (APNS certificate application process reference: https://www.pushwoosh.com/programming-push-notification/ ios/ios-configuration-guide/); The certificate request steps for VoIP push are as follows:


2. Use this certificate to export and load to the push server, the server side does not need to make changes, only to replace the certificate-related things (the process and the previous APNs certificate loading completely similar); the interaction process between the server and the client is almost identical.

3. Client implementation:

Step1: Add Pushkit in the project;

Step2: Add VoIP, Backgroundfetch, remotenotifications support to the Backgroundmode inside the project setup.

Step3: For insurance purposes, developers are advised to use the latest version of Xcode and the latest SDK, and it is recommended to reapply for a mobile provision file for packaging.

Step4: Similar to the APNS notification of the client implementation process, the VoIP push client-related process is similar: Registering VoIP push notifications, implementing Pushkit related agents.

Post the main code:

The following code is called after application startup (Appdelegate Didfinishlaunchwithoptions) or initialization of the root controller:
Pkpushregistry *pushregistry = [[Pkpushregistry alloc] Initwithqueue:dispatch_get_main_queue ()];
Pushregistry.delegate = self;
Pushregistry.desiredpushtypes = [Nsset Setwithobject:pkpushtypevoip];

Uiusernotificationsettings *usernotifysetting = [uiusernotificationsettings settingsfortypes: Uiusernotificationtypebadge | Uiusernotificationtypesound | Uiusernotificationtypealert Categories:nil];
[[UIApplication sharedapplication] registerusernotificationsettings:usernotifysetting];
The above code implements the registration of VoIP push when the app is launched;

To implement a proxy for VoIP push in the Appdelegate or framework Viewcontroller class:

@interface eptabbarcontroller:uitabbarcontroller<pkpushregistrydelegate>

-(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"];

}

Our docking push server here is the service provided by Zeropush, we will introduce the service in the following, the proxy method is that the device obtains the VoIP token from Apple server and then passes it to the application We need to pass this token to the push server (similar to the APNs push, we are also going to pass the APNs token to the push server, but the two tokens are obtained in different ways, callback to the application in different proxy methods, And the contents of these two tokens are also different).

After the push server obtains the user's VoIP token, under all normal circumstances, another callback is triggered when the push server sends a message to the token-corresponding device.


-(void) Pushregistry: (Pkpushregistry *) Registry didreceiveincomingpushwithpayload: (Pkpushpayload *) payload Fortype: (NSString *) type
{
 
    NSLog (@ "Didreceiveincomingpushwithpayload");
   //VoIP registration at this time

   //write your VoIP related codes here
    < br>    uiusernotificationtype thetype = [UIApplication sharedapplication]. Currentusernotificationsettings.types;
    if (thetype = = Uiusernotificationtypenone)
    {
         uiusernotificationsettings *usernotifysetting = [uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge | Uiusernotificationtypesound | Uiusernotificationtypealert Categories:nil];
        [[UIApplication sharedapplication] Registerusernotificationsettings:usernotifysetting];
   }


Uilocalnotification *backgroudmsg = [[Uilocalnotification alloc] init];
backgroudmsg.alertbody= nsinternationalstring (@ "You receive a new call", nil);
[[UIApplication sharedapplication] presentlocalnotificationnow:backgroudmsg];

}

The above callback code only prints the log, triggering a local notification, this proxy method is triggered when the VoIP push notification is received, and if everything is OK, the notification will be triggered when the phone restarts, the application is reclaimed by the system, and the manual kill program. And can be used for a period of time to execute their own code (such as VoIP registration, etc.).

We are here to design a simple business for your reference, mainly to allow you to intuitively recognize the ability of Pushkit:

1. The applied VoIP long connection is not maintained and is connected when the call is received or the call is initiated;

2. When the call is sent to the VoIP server, the peer is not online, connected to the Pushserver by the VoIP server to send a push notification to the end;

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

4. The caller through the delay operation and other logic (complex point to the VoIP server transformation, called to connect up to notify the caller to the side), the call again, the call is successfully established.


Introduction to zero push: https://www.zeropush.com/

Technical support email for zero push: [email protected]

I have a certificate related issues to try to send the mailbox, and soon got a satisfactory response, very good!

Zero Push provides a free trial service, which allows us to experience VoIP push very conveniently;

Follow its prompts to register an account, then create an app, upload a VoIP certificate, get its apikey from the webpage (this key is used before uploading tokens, in the proxy method above).

Here is an introductory article on VoIP push, and the following is the GitHub link to the demo project:

Https://www.zeropush.com/guide/guide-to-pushkit-and-voip

It should be noted that the project is written in the Swift language, if your certificate and provision files are previously requested, only for OC-created projects, then the project will likely be out of the way when the real-life is running, the workaround is to regenerate your certificate and provision file, and use it in the project, and then repackage it, the problem is solved.


Finally, we welcome any form of discussion about this subject ~ I notice that the Chinese information on this subject or practice summary is very little, most of them are in English, and we hope that together with the accumulation of common progress ~

My e-mail: [Email protected]






iOS8 new features: Pushkit Combat Summary (VoIP developer must read)

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.