Sausage Machine Sausage Machine - 1 year ago 124
iOS Question

How does the TrueCaller action extension launch the TrueCaller container app?

All the past questions regarding launching the container app from its extension summarize that Apple state that only certain types of extension can launch their container app using the extension context i.e.

let url = URL.init(string: "AppScheme://")
self.extensionContext?.open(url!, completionHandler: { (resultBool) in

The conclusion is it works for hardly any extension types, and it does not work for an action or share extension. I tried it myself using the above code in an action extension and sure enough it didn't work, (I can launch the app from Safari, so the url scheme for the app is working).

However the Truecaller app's extension can launch its container app (the extension is invoked from the Phone app's call history, share contact option. Once the extension is displayed the user can click on a button and the Truecaller container app is launched).

So it is possible. But how is Truecaller doing it?

Answer Source

I found a way, this works on iOS 10

NSURL *destinationURL = [NSURL URLWithString:@"NameID://"];

// Get "UIApplication" class name through ASCII Character codes.
NSString *className = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned char []){0x55, 0x49, 0x41, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E} length:13] encoding:NSASCIIStringEncoding];
if (NSClassFromString(className)) {
    id object = [NSClassFromString(className) performSelector:@selector(sharedApplication)];
    [object performSelector:@selector(openURL:) withObject:destinationURL];

Taken from: openURL not work in Action Extension

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download