最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Amazon SNS的VoIP推送

IT培训 admin 61浏览 0评论

Amazon SNS的VoIP推送

我正在尝试从Amazon SNS发送VoIP推送,有firebase功能,该功能会在接收到VoIP_token时创建ARN,并使SNS推送VoIP推送。现在我面临一个问题。

=> push进入didReceiveIncomingPushWith有效载荷内部,但是在此委托方法内部,我正尝试更新firebase值,正如您在代码中看到的那样,此方法也有效,android从已在SNS中配置的SNS发送5分钟后发送push firebase功能,但问题是有时有时会推送,有时不是,在开发版本中它工作正常,但是当我进行试飞时,它经常工作

扩展名AppDelegate:PKPushRegistryDelegate {

@available(iOS 8.0, *)
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
    if #available(iOS 10.0, *) {
        Timer.scheduledTimer(withTimeInterval: 30, repeats: true) {_ in
            self.myMethod()
        }
    }
    else {
        Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(self.myMethod), userInfo: nil, repeats: true)
    }

    let token = credentials.token.map { String(format: "%02x", $0) }.joined()

    voipTokenLogin = token
    voip_Token = token
    UserDefaults.standard.set(voipTokenLogin, forKey: "voip_Push_From_Amazon_SNS")
    var objRef : DatabaseReference!
    _ = String()

    if MyCurrentUSERID != "" && isUserLoggedIn {
        objRef = Database.database().reference().child("user").child(MyCurrentUSERID)
        let battery = UIDevice.current.batteryLevel * 100
        let Intbattery = Int(battery)
        let dict = [
            "isOnline" : true,
            "isGps" : true,
            "voip_token": voip_Token,
            "Battery" : Intbattery,
            "lastSeen" : Int(Date().millisecondsSince1970),
            "timeStamp" : Date().millisecondsSince1970
            ] as [String : Any]
        objRef.updateChildValues(dict)
    }
    else{
    }
}

@available(iOS 8.0, *)

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void){
    var arrTemp = [AnyHashable: Any]()
    arrTemp = payload.dictionaryPayload
    let _ : Dictionary <String, AnyObject> = arrTemp["aps"] as! Dictionary<String, AnyObject>
    if isUserHasLoggedInWithApp // Check this flag then only proceed
    {
        if UIApplication.shared.applicationState == UIApplicationState.background || UIApplication.shared.applicationState == UIApplicationState.inactive
        {
            if checkForIncomingCall
            {
                Locator.currentPosition(accuracy: .city, onSuccess: { (loc) -> (Void) in
                    isUpdatedUsingSilentPush = true

                    if self.isUserLoggedIn{
                        if !isUploadingRecentLocation {
                            if !self.sendOneUpdate{
                    self.sendLocationToFirebase(manager: Locator, Location: loc)
                            }
                        }
                    }

                }) { (err, loct) -> (Void) in
                    print(err)
                    print(loct as Any)
                }
                //
                var objRef : DatabaseReference!
                if MyCurrentUSERID != "" {
                    objRef = Database.database().reference().child("user").child(MyCurrentUSERID)
                    let dict = [
                        "timeStamp" : Date().millisecondsSince1970,
                        "isOnline" : true,
                        "isGps" : true,
                        "lastSeen" : Int(Date().millisecondsSince1970)
                        ] as [String : Any]

                    objRef.updateChildValues(dict)

                      var strTitle : String = dict["alertTitle"] as? String ?? "\(MyCurrentUSERID)"
                    let strBody : String = dict["alertBody"] as? String ?? "push arrived successfully"
                    strTitle = strTitle + "\n" + strBody
                    self.myMethod()
                    let notificationIncomingCall = UILocalNotification()
                    notificationIncomingCall.fireDate = Date(timeIntervalSinceNow: 1)
                   notificationIncomingCall.alertBody =  strTitle
                    notificationIncomingCall.alertAction = "Open"
                    notificationIncomingCall.soundName = "SoundFile.mp3"
                    notificationIncomingCall.category = dict["category"] as? String ?? ""
                    //"As per payload you receive"
                    notificationIncomingCall.userInfo = ["key1": "Value1"  ,"key2": "Value2" ]
                UIApplication.shared.scheduleLocalNotification(notificationIncomingCall)
                }

            }
            else
            {
                //  something else
            }

        }
    }
    completion()
}
回答如下:

您使用Xcode 11和iOS13吗?苹果对VoIP推送通知进行了重大更改。使用VoIP时,您需要向CallKit报告“来电”。

在iOS 13.0及更高版本上,如果您无法报告对CallKit的呼叫,系统将终止您的应用。反复未能报告呼叫可能会导致系统停止向您的应用传递更多VoIP推送通知。如果要在不使用CallKit的情况下发起VoIP呼叫,请使用UserNotifications框架而不是PushKit注册推送通知。

https://developer.apple/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry

Amazon SNS的VoIP推送

我正在尝试从Amazon SNS发送VoIP推送,有firebase功能,该功能会在接收到VoIP_token时创建ARN,并使SNS推送VoIP推送。现在我面临一个问题。

=> push进入didReceiveIncomingPushWith有效载荷内部,但是在此委托方法内部,我正尝试更新firebase值,正如您在代码中看到的那样,此方法也有效,android从已在SNS中配置的SNS发送5分钟后发送push firebase功能,但问题是有时有时会推送,有时不是,在开发版本中它工作正常,但是当我进行试飞时,它经常工作

扩展名AppDelegate:PKPushRegistryDelegate {

@available(iOS 8.0, *)
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
    if #available(iOS 10.0, *) {
        Timer.scheduledTimer(withTimeInterval: 30, repeats: true) {_ in
            self.myMethod()
        }
    }
    else {
        Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(self.myMethod), userInfo: nil, repeats: true)
    }

    let token = credentials.token.map { String(format: "%02x", $0) }.joined()

    voipTokenLogin = token
    voip_Token = token
    UserDefaults.standard.set(voipTokenLogin, forKey: "voip_Push_From_Amazon_SNS")
    var objRef : DatabaseReference!
    _ = String()

    if MyCurrentUSERID != "" && isUserLoggedIn {
        objRef = Database.database().reference().child("user").child(MyCurrentUSERID)
        let battery = UIDevice.current.batteryLevel * 100
        let Intbattery = Int(battery)
        let dict = [
            "isOnline" : true,
            "isGps" : true,
            "voip_token": voip_Token,
            "Battery" : Intbattery,
            "lastSeen" : Int(Date().millisecondsSince1970),
            "timeStamp" : Date().millisecondsSince1970
            ] as [String : Any]
        objRef.updateChildValues(dict)
    }
    else{
    }
}

@available(iOS 8.0, *)

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void){
    var arrTemp = [AnyHashable: Any]()
    arrTemp = payload.dictionaryPayload
    let _ : Dictionary <String, AnyObject> = arrTemp["aps"] as! Dictionary<String, AnyObject>
    if isUserHasLoggedInWithApp // Check this flag then only proceed
    {
        if UIApplication.shared.applicationState == UIApplicationState.background || UIApplication.shared.applicationState == UIApplicationState.inactive
        {
            if checkForIncomingCall
            {
                Locator.currentPosition(accuracy: .city, onSuccess: { (loc) -> (Void) in
                    isUpdatedUsingSilentPush = true

                    if self.isUserLoggedIn{
                        if !isUploadingRecentLocation {
                            if !self.sendOneUpdate{
                    self.sendLocationToFirebase(manager: Locator, Location: loc)
                            }
                        }
                    }

                }) { (err, loct) -> (Void) in
                    print(err)
                    print(loct as Any)
                }
                //
                var objRef : DatabaseReference!
                if MyCurrentUSERID != "" {
                    objRef = Database.database().reference().child("user").child(MyCurrentUSERID)
                    let dict = [
                        "timeStamp" : Date().millisecondsSince1970,
                        "isOnline" : true,
                        "isGps" : true,
                        "lastSeen" : Int(Date().millisecondsSince1970)
                        ] as [String : Any]

                    objRef.updateChildValues(dict)

                      var strTitle : String = dict["alertTitle"] as? String ?? "\(MyCurrentUSERID)"
                    let strBody : String = dict["alertBody"] as? String ?? "push arrived successfully"
                    strTitle = strTitle + "\n" + strBody
                    self.myMethod()
                    let notificationIncomingCall = UILocalNotification()
                    notificationIncomingCall.fireDate = Date(timeIntervalSinceNow: 1)
                   notificationIncomingCall.alertBody =  strTitle
                    notificationIncomingCall.alertAction = "Open"
                    notificationIncomingCall.soundName = "SoundFile.mp3"
                    notificationIncomingCall.category = dict["category"] as? String ?? ""
                    //"As per payload you receive"
                    notificationIncomingCall.userInfo = ["key1": "Value1"  ,"key2": "Value2" ]
                UIApplication.shared.scheduleLocalNotification(notificationIncomingCall)
                }

            }
            else
            {
                //  something else
            }

        }
    }
    completion()
}
回答如下:

您使用Xcode 11和iOS13吗?苹果对VoIP推送通知进行了重大更改。使用VoIP时,您需要向CallKit报告“来电”。

在iOS 13.0及更高版本上,如果您无法报告对CallKit的呼叫,系统将终止您的应用。反复未能报告呼叫可能会导致系统停止向您的应用传递更多VoIP推送通知。如果要在不使用CallKit的情况下发起VoIP呼叫,请使用UserNotifications框架而不是PushKit注册推送通知。

https://developer.apple/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论