有人可以在C#中共享iOS Xamarin PushKit的示例代码吗?

本文关键字:PushKit 代码 Xamarin iOS 共享 | 更新日期: 2023-09-27 17:55:55

我正在尝试在我的ios应用程序中实现PushKit。但是,PushKit 的 Xamarin 文档非常有限。您是否有如何在 Xamarin C# 中使用它的示例代码?多谢。

有人可以在C#中共享iOS Xamarin PushKit的示例代码吗?

您可以从

以下链接中获得想法斯威夫特代码捆绑

如果你有纯 swift 代码,那么你可以从下面的链接下载示例代码。

下载

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

}
}