2016-12-28 4 views
2

Dans mon projet XCode, j'ai utilisé la méthode setKeepAliveTimeout en méthode applicationDidEnterBackground comme ci-dessous le code.Comment remplacer la méthode UIRemoteNotificationTypeVoip avec la méthode setKeepAliveTimeout?

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

Il montre que la méthode setKeepAliveTimeout est dépréciée et ils veulent utiliser la méthode UIRemoteNotificationTypeVoip.

J'ai recherché la méthode UIRemoteNotificationTypeVoip, mais pas assez de résultats sont donnés. Même developer.apple.com n'a pas de documentation pour cette méthode.

Problème: Comment changer UIRemoteNotificationTypeVoipsetKeepAliveTimeout est utilisé?

Si quelqu'un le sait, donnez-moi une réponse.

Merci à l'avance!

+0

Travaillez-vous sur l'application basée sur VOIP? then setKeepAliveTimeout ne vous aidera qu'à l'état d'arrière-plan. Si vous voulez que votre application basée sur VOIP fonctionne également à l'état Terminé, vous devez intégrer Pushkit. – Hasya

+0

Son application basée sur VOIP seulement, mais Apple était maintenant dépréciée la méthode setKeepAliveTimeout. Au lieu de la méthode setKeepAliveTimeout, ils ont introduit la méthode UIRemoteTypeNotificationVoip. Donc, je veux que comment implémenter la méthode UIRemoteTypeNotificationVoip. – NandhaKumar

+0

setKeepAliveTimeout ou UIRemoteTypeNotificationVoip, votre application ne fonctionnera pas à des fins VOIP dans un état terminé. vous devez travailler avec Pushkit. Voir https://github.com/hasyapanchasara/PushKit_SilentPushNotification – Hasya

Répondre

2

Utilisez la structure ci-dessous pour accomplir votre tâche.

Certains référence

https://github.com/hasyapanchasara/PushKit_SilentPushNotification

enter image description here

enter image description here

Utilisez ce fichier simplepush.php

Utilisez les commandes ci-dessous pour créer un fichier .pem et de l'utiliser dans le code ci-dessus .

Après cela, allez à simplepush.php emplacement et commande feu -> php simplepush.php

De cette façon, vous pouvez tester votre architecture de configuration de notification kit push.

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 

} 

} 

Grâce à la charge utile de pushkit vous pouvez programmer une notification locale. Lorsque la charge utile pushkit arrive, votre application est active en arrière-plan ou à l'état terminé jusqu'à vos lectures sonores locales. vous pouvez également conserver les détails dans NSUserDefault. donc sur la notification locale interactive ou didfinishlaunching avec option, vous pouvez faire ce que vous voulez.

+0

pouvez-vous s'il vous plaît modifier ce code à l'objectif c @hashya – NandhaKumar

+0

Quelque chose pourrait vous aider, voir http://stackoverflow.com/questions/27245808/implement-pushkit-and-test-in-development-behavior – Hasya

+1

cela fonctionne! Je remplace les méthodes des méthodes CallKit dans mon AppDelegate.m et obtiens le jeton de périphérique using PKPushRegistry des APNs. Cela fonctionne parfaitement dans mon application VOIP. – NandhaKumar