I'm a beginner in both ObjectiveC and Swift (but have to develop an iOS share extension for a Cordova app).
I'm trying to implement this code snippet in my share extension
NSURL *destinationURL = [NSURL URLWithString:@"myapp://"];
// 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];
}
For now I have the following, but I don't really know how to translate the "performSelector" part as it seems it's not in Swift.
let bytesArray : [UInt8] = [0x55, 0x49, 0x41, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E]
let classNameNs = NSString.init(data: NSData(bytes: bytesArray, length: bytesArray.count), encoding: NSASCIIStringEncoding) ?? ""
let className = classNameNs as String
NSClassFromString(className).map { clazz in
let result = clazz.performSelector(Selector("sharedApplication"))
}
Can someone help me complete this part please? thanks