3

In my XCode project, i have used setKeepAliveTimeout method in applicationDidEnterBackground method like below code.

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];

    [application setKeepAliveTimeout:600 handler: ^{
    [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
    }];
}

It shows that setKeepAliveTimeout method is deprecated and they wants to use UIRemoteNotificationTypeVoip method.

I searched for UIRemoteNotificationTypeVoip method, but not enough results are given. Even developer.apple.com doesn't have documentation for that method.

Problem: How to change UIRemoteNotificationTypeVoip where setKeepAliveTimeout is used?

If anyone knows, then give me an answer.

Thanks in Advance!

Hasya
  • 9,792
  • 4
  • 31
  • 46
Nandhakumar Kittusamy
  • 1,066
  • 12
  • 32
  • Are you working on VOIP based app? then setKeepAliveTimeout will help in background state only, If you want your VOIP based app works in terminated state as well then you need to integrate Pushkit. – Hasya Jan 19 '17 at 06:59
  • Its VOIP based app only, but apple was now deprecated the setKeepAliveTimeout method. Instead of setKeepAliveTimeout method, they introduced UIRemoteTypeNotificationVoip method. So i want that how to implement UIRemoteTypeNotificationVoip method. – Nandhakumar Kittusamy Jan 19 '17 at 07:03
  • setKeepAliveTimeout or UIRemoteTypeNotificationVoip, your app will not work for VOIP purpose in terminated state. you have to work with Pushkit. See https://github.com/hasyapanchasara/PushKit_SilentPushNotification – Hasya Jan 19 '17 at 07:07
  • if the incoming call occurs to the app, pushkit works for that? – Nandhakumar Kittusamy Jan 19 '17 at 07:20
  • Through pushkit payload you can schedule local notification. when pushkit payload comes your app will active in background or terminated state upto your local notification sound plays. you can also keep details in NSUserDefault. so on interactive local notification or didfinishlaunching with option you can do whatever you want. – Hasya Jan 19 '17 at 07:23
  • Get whole procedure step by step from my answer. Don't forget to accept answer if helped you. – Hasya Jan 19 '17 at 07:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/133520/discussion-between-nandha-kumar-and-hasya). – Nandhakumar Kittusamy Jan 19 '17 at 07:28

1 Answers1

2

Use below structure to achieve your task.

Some reference

https://github.com/hasyapanchasara/PushKit_SilentPushNotification

enter image description here

enter image description here

Use this simplepush.php file

Use below commands to create pem file and use it in above code.

After that go to simplepush.php location and fire command -> php simplepush.php

This way you can test your push kit notification setup architecture.

https://zeropush.com/guide/guide-to-pushkit-and-voip

https://www.raywenderlich.com/123862/push-notifications-tutorial

Download

import UIKit
import PushKit


class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate{



func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {


    let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
    application.registerForRemoteNotificationTypes(types)

    self. PushKitRegistration()

    return true
}



//MARK: - PushKitRegistration

func PushKitRegistration()
{

    let mainQueue = dispatch_get_main_queue()
    // Create a push registry object
    if #available(iOS 8.0, *) {

        let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)

        // Set the registry's delegate to self

        voipRegistry.delegate = self

        // Set the push type to VoIP

        voipRegistry.desiredPushTypes = [PKPushTypeVoIP]

    } else {
        // Fallback on earlier versions
    }


}


@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
    // Register VoIP push token (a property of PKPushCredentials) with server

    let hexString : String = UnsafeBufferPointer<UInt8>(start: UnsafePointer(credentials.token.bytes),
        count: credentials.token.length).map { String(format: "%02x", $0) }.joinWithSeparator("")

    print(hexString)


}


@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
    // Process the received push
    // From here you have to schedule your local notification

}

}

Through pushkit payload you can schedule local notification. when pushkit payload comes your app will active in background or terminated state upto your local notification sound plays. you can also keep details in NSUserDefault. so on interactive local notification or didfinishlaunching with option you can do whatever you want.

Hasya
  • 9,792
  • 4
  • 31
  • 46