0

We are developing a voip calling app. We are using CallKit and PushKit frameworks. A user recently reported that his iPhone is not receiving CallKit push anymore, but few days ago that was working. Please note mutable push is working on his device. We have collected device's console logs and learned that device did not receive voip push payload.

No firewalls installed and no recent change history of network settings.

Environments info:

Device Model: iPhone Xs
iOS version: 15.6.1
Network Connectivity: Wifi

This is how we registered PushKit

    private func registerForVoIPPushes() {
        self.voipRegistry = PKPushRegistry(queue: pushRegistryQueue)
        self.voipRegistry.delegate = self
        self.voipRegistry.desiredPushTypes = [.voIP]
    }

We conforms the PKPushRegistryDelegate this way

extension AppDelegate: PKPushRegistryDelegate {
    func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        let deviceToken = pushCredentials.token.map { String(format: "%02x", $0) }.joined()        
        updateVoIPToken(deviceToken)
    }
    
    func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
        DDLogDebug("Incoming call voip push: \(payload.dictionaryPayload)")
        handleIncomingCall(payload: payload.dictionaryPayload)
        completion()
    }
    
    func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
        DDLogDebug("didInvalidatePushTokenFor type: \(type)")
    }
}

This is how server sends voip push payload

path = '/3/device/{0}'.format({deviceToken}})

request_headers = {
    'apns-expiration': '0',
    'apns-priority': '10',
    'apns-topic': 'com.companyname.app.voip',
    'apns-push-type':'voip',
    'authorization': 'bearer {auth-token}'
}

# Open a connection the APNS server
conn = HTTP20Connection('api.push.apple.com:443')
conn.request(
    'POST', 
    path, 
    payload, 
    headers=request_headers
)
resp = conn.get_response()
print(resp.status)
print(resp.read())

The output http status code shows 200 but push actually not delivered. Same codebase is woking fine with other devices.

I appreciate any helps and suggestions.

Thanks.

Shamim Hossain
  • 1,690
  • 12
  • 21
  • 1
    It sounds like the device may not be connected to the internet. Can you check to see if the device is connected to the internet? If not, try connecting it to the internet and see if that fixes the problem. – Mohamed Elgazar Oct 16 '22 at 11:55
  • Thanks @MohamedElgazar for your response. The device was connected with a WIFI network. – Shamim Hossain Oct 16 '22 at 17:00
  • Shamim bhai, the possible reason may be "Since you said did not receive voip push payload, that means when server send to APNS , apns is rejecting it. Just find out why APNS is rejecting the push. It either may be device token invalid or didReceiveIncomingPushWith not getting called. You can set content-available = 1 to the push payload while sending from server to APNS" – Mohammad Daihan Jun 13 '23 at 09:56
  • I mentioned that voip push sending was successful `200` in the description. If the device token invalidates, the APNS response code will be around 4XX, which did not happen. I could not understand why I have to use `content-available = 1`? – Shamim Hossain Jun 14 '23 at 01:03
  • Bhai i was facing this kind of issues my didReceiveIncoming push was not getting called, after adding content-available to true didReceiveIncoming push was getting called. You can check this answer https://stackoverflow.com/a/65777591/14206959 – Mohammad Daihan Jun 14 '23 at 06:52
  • @MohammadDaihan you are mixing with VoIP and background push. VoIP push is a different type of push handled by PushKit. – Shamim Hossain Jun 15 '23 at 06:54
  • As far as i know: আমাদের সার্ভার একটা VoIP push payload generate করে APNS কে দিবে । APNS VoIP push টা ডিভাইসে পাঠাবে তখন ডিভাইসে iOS অপারেটিং সিস্টেম payload এর প্যাটার্ন দেখে ডিটেক্ট করবে যে এটা voip push নাকি apple push notification ? যদি voip push হয় তবে app এর ভিতরে PKPushRegistryDelegate এর didReceiveIncomingPushWith ফাংশন কল হবে , এই ফাংশনের ভিতর থেকে রেন্ডম কল আইডি জেনারেট করে CallKit রিপোর্ট করে দিব , CallKit এ রিপোর্ট করার সাথে সাথে app যদি ব্যাকগ্রাউন্ড থেকে কিল করা অবস্থায় থাকে তবে iOS অপারেটিং সিস্টেম এপ্টাকে 30 second এর জন্য ব্যাকগ্রাউন্ডে লাইভ করে দিবে । – Mohammad Daihan Jun 15 '23 at 09:48
  • তখন এপের Appdelegate class এর didFinishLaunchingWithOptions এবং SceneDelegate এর willConnectTo session ফাংশন কল হয় । তো আমাদের কাজ হল didFinishLaunchingWithOptions অথবা willConnectTo session ফাংশনে websocket এর সাথে কানেক্ট করে দিব এবং লগিন প্যাকেট যা যা পাঠানো দরকার তা পাঠিয়ে দিব । websocket যখনই কানেক্ট হবে তখন websocket এর didReceive delegate মাধ্যমে SDP এর প্যাকেট টা আসবে । তখন আমরা সেইম কল আইডি দিয়ে আবার CallKit এ রিপোর্ট করব । তখনই আমাদের call widget স্ক্রিন চলে আসবে । – Mohammad Daihan Jun 15 '23 at 09:50
  • Bhai if you have some good tutorial about voip push, could you please provide me ? I want to learn more about this topic – Mohammad Daihan Jun 15 '23 at 09:51
  • @MohammadDaihan it's not that easy. So many iOS components are related to CallKit, for example, Audio Session. Anyways, there is not much documentation for this topic. https://developer.apple.com/documentation/pushkit – Shamim Hossain Jun 16 '23 at 09:17

1 Answers1

0
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
    NSLog("pushRegistry:didUpdatePushCredentials:forType:")
    let deviceToken = credentials.token.map { String(format: "%02.2hhx", $0) }.joined()
    print("\(#function) token is: \(deviceToken)")
}
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 23 '23 at 17:59
  • We are already using this delegate. We upload this device token to the backend server for sending voip push notification. – Shamim Hossain Aug 15 '23 at 03:47