iOS VoIP推送通知(推送套件)
我正在搜索VoIP推送通知的推送通知信息。有一点我还不清楚: 1) 如果用户尚未打开应用程序,则会收到一个呼叫。是否有办法从通知中启动应用程序 2) 应用程序如何等待特定事件?例如,我的设备如何知道他收到某人的电话 3) 我使用来自的Appdelegate文件,但在我的情况下,它不起作用(许多错误),是我得到的错误的预览 如果用户尚未打开应用程序,然后他收到了一个电话,则表示感谢。是否有办法从通知中启动应用程序 -用户第一次必须点击应用程序图标并打开它,然后只有设备id才能获得寄存器以接收推送套件负载。那么就不需要打开应用程序了。当应用程序处于终止状态,并且您必须根据推送套件负载安排本地通知时,它也会工作。 2) 应用程序如何等待特定事件?例如,我的设备如何知道他收到某人的电话 -您必须根据推送套件负载安排本地通知。 3) 我使用来自的Appdelegate文件,但在我的情况下它不起作用(许多错误),这里是我得到的错误预览 -参考以下代码iOS VoIP推送通知(推送套件),ios,swift,notifications,pushkit,Ios,Swift,Notifications,Pushkit,我正在搜索VoIP推送通知的推送通知信息。有一点我还不清楚: 1) 如果用户尚未打开应用程序,则会收到一个呼叫。是否有办法从通知中启动应用程序 2) 应用程序如何等待特定事件?例如,我的设备如何知道他收到某人的电话 3) 我使用来自的Appdelegate文件,但在我的情况下,它不起作用(许多错误),是我得到的错误的预览 如果用户尚未打开应用程序,然后他收到了一个电话,则表示感谢。是否有办法从通知中启动应用程序 -用户第一次必须点击应用程序图标并打开它,然后只有设备id才能获得寄存器以接收推送套
import UIKit
import PushKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate {
var window: UIWindow?
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
}
}
导入UIKit
导入推送套件
@UIApplicationMain
类AppDelegate:UIResponder、UIApplicationDelegate、PKPushRegistryDelegate{
变量窗口:UIWindow?
func应用程序(应用程序:UIApplication,didFinishLaunchingWithOptions启动选项:[NSObject:AnyObject]?)->Bool{
let类型:UIRemoteNotificationType=[.Alert、.Badge、.Sound]
application.registerForRemoteNotificationTypes(类型)
self.pushkit注册()
返回真值
}
//马克:注册
func pushkit注册()
{
让mainQueue=dispatch\u get\u main\u queue()
//创建推送注册表对象
如果可用(iOS 8.0,*){
让voipRegistry:PKPushRegistry=PKPushRegistry(队列:mainQueue)
//将注册表的委托设置为self
voipRegistry.delegate=self
//将推送类型设置为VoIP
voipRegistry.desiredPushTypes=[PKPushTypeVoIP]
}否则{
//对早期版本的回退
}
}
@可用(iOS 8.0,*)
func pushRegistry(注册表:PKPushRegistry!,didUpdatePushCredentials:PKPushCredentials!,forType:String!){
//向服务器注册VoIP推送令牌(PKPushCredentials的属性)
让hexString:String=UnsafeBufferPointer(开始:UnsafePointer(credentials.token.bytes)),
计数:credentials.token.length).map{String(格式:'%02x',$0)}.joinWithSeparator(“”)
打印(十六进制字符串)
}
@可用(iOS 8.0,*)
func pushRegistry(注册表:PKPushRegistry!,didReceiveIncomingPushWithPayload:PKPushPayload!,forType:String!){
//处理接收到的推送
}
}
获取有关如何为基于VOIP的应用程序集成pushkit的更多信息
刚刚更新了Swift 4.0代码
看,这个太宽了!嘿,我需要你在voip通知方面的帮助。好的,你的查询是什么?当voip通知到来时,应用程序没有打开