2016-08-31 8 views
0

は、私はdidFinishLaunchingWithOptions内のコードを追加し、PushKitフレームワークを使用しています通知を受け取ったときにPushKitを処理しますか?

let voipRegistry: PKPushRegistry = PKPushRegistry(queue: dispatch_get_main_queue()) 
    voipRegistry.delegate = self 
    voipRegistry.desiredPushTypes = NSSet(object: PKPushTypeVoIP) as! Set<NSObject> 

//トークンを登録

func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) { 

     } 

//通知

func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) { 
      let content = payload.dictionaryPayload["aps"] as? Dictionary<String,String> 
      let message = content!["alert"] 

      let notification = UILocalNotification() 
      notification.alertTitle = "Hifi" 
      notification.alertBody = message 
      notification.alertLaunchImage = "logo_white.png" 
      notification.soundName = "Glass.caf" 
      UIApplication.sharedApplication().presentLocalNotificationNow(notification) 

}

を受けるIそのように実装されていますが、受信していませんg通知 didReceiveIncomingPushWithPayloadデリゲートメソッドで通知を処理する方法は?

答えて

0

また、あなたのペムと別のものをチェックしてください。

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 


} 

} 

Life cycle of app - when app is in terminated and push kit payload comes

を通過します
関連する問題