问题
We have a VoIP app where we are currently using standard push notifications. We would like to update to using PushKit and VoIP push notifications. I'm a bit unsure how to migrate from our current standard APNS setup to the new. Questions:
1) Will our current APNS production certificate be able to send push messages to new VoIP clients?
2) Will our new VoIP push certificate be able to send push messages to existing, standard APNS apps (tokens)?
回答1:
Please do refer pushkit demo https://github.com/hasyapanchasara/PushKit_SilentPushNotification
Objective c demo is also there https://github.com/hasyapanchasara/PushKit_SilentPushNotification/tree/master/Objective%20C%20Demo/PushKitDemoObjectiveC
Below is swift code to register for push kit and receive pushkit payload.
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
}
}
When your app is based on VOIP, then once you receive pushkit payload then you can schedule local notification. As per interactive local notification you can receive, disconnect etc feature can process ( Same like Whatsapp, Skype etc ).
1) Will our current APNS production certificate be able to send push messages to new VoIP clients?
- No, you have to create pem file and configure at back end as well.
2) Will our new VoIP push certificate be able to send push messages to existing, standard APNS apps (tokens)?
- No, Pushkit tokens will be different from APNS tokens.
- List item
Refer more for Debug, Certificate, Local notification
https://github.com/hasyapanchasara/PushKit_SilentPushNotification
来源:https://stackoverflow.com/questions/43039951/migrate-to-ios-voip-push-notifications