Я пытаюсь отправить VoIP push-запрос от Amazon SNS, есть функция firebase, которая создает ARN при получении VoIP_token, и она заставляет SNS push-запрос VoIP. теперь есть одна проблема, с которой я сталкиваюсь.
=> push идет внутри полезной нагрузки didReceiveIncomingPushWith, но внутри этого метода делегата я пытаюсь обновить значение firebase, как вы можете видеть в коде, это также работает, androidотправляет push через 5 минут из SNS, который был сконфигурирован в функции firebase, но проблема в том, что push иногда приходит, а иногда нет, в разрабатываемой версии он работает нормально, но когда я выполняю тестовый полет, он часто работает с расширением
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()
}