Dynamically casting classes

Hello everybody :wave:

Not sure if this is the right forum to ask my question, please give me feedback if this is OT. Ok, now my problem. I'm currently updating our CallKit based app for iOS 13 and found the following problem: If you try to call any contact from the Contacts.app in iOS 13 with your CallKit app, it will NOT get any contact information (and will not be able to call your contact then). Why? Apple changed the intent from INStartAudioCallIntent to INStartCallIntent. I tried to fix this by extending the case statement handling intents:

// iOS < 13.0
case "INStartAudioCallIntent":
  if let to = (userActivity.interaction?.intent as! INStartAudioCallIntent).contacts?.first?.personHandle?.value {
    // logic

// iOS > 13.0
case "INStartCallIntent":
  if let to = (userActivity.interaction?.intent as? INStartCallIntent).contacts?.first?.personHandle?.value {
    // logic

I can't compile this using Xcode 10 because INStartCallIntent is not available. Compiling with Xcode 11 beta is also a no-go as Apple does not accept apps compiled with Xcode 11 yet. Wrapping this in an if #available statement does not work either as Xcode still complains about the missing type. I also tried combining the two cases, however this results in crashing the app as a INStartCallIntent can not be casted to a INStartAudioCallIntent.

It looks like the official Skype app has the same problem though, as calling from the Contacts.app does not work in the iOS beta. WhatsApp however does work, and I think this because WhatsApp is still built in Objective-C which does clearly not have this problems.

Any ideas how to fix this? Is there a way to dynamically cast in Swift?

Probably better to ask at StackOverFlow or Apple developer forums. Question has to do with Apple tools and frameworks, and not Swift per se. In my mind, I would wait for Xcode 11 to be officially released, which should be soon.

If you want to cast to a class, the class needs to be declared somewhere. You could try copying the the INStartCallIntent class declaration to your bridging header so Swift can see it. You'll need to remove it from the bridging header for compiling with Xcode 11 though.

Terms of Service

Privacy Policy

Cookie Policy