iOS 18 ShareExtension openURL:

When I write code in shareExtension like below: dispatch_async(dispatch_get_global_queue(0, 0), ^{ UIResponder *responder = [self nextResponder]; while ((responder = [responder nextResponder]) != nil) { if ([responder respondsToSelector:@selector(openURL:)] == YES) { [responder performSelector:@selector(openURL:) withObject:[NSURL URLWithString:APP_SCHEME]]; break; } } });

Will output in the console:

BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(:) needs to migrate to the non-deprecated UIApplication.open(:options:completionHandler:). Force returning false (NO).

Answered by DTS Engineer in 806197022

Looking on the bright side of things, you’ve learnt a key compatibility lesson. Sadly, you had to learn that the hard way )-:

The UIApplication object is explicitly marked as unavailable from an app extension. If you add code to an app extension that tries to open a URL in the normal way, using UIApplication.shared.open(_:), it’ll fail to build. You’ve used the Objective-C runtime to bypass that build-time restriction, and that’s now failing.

App extensions are not allowed to open URLs directly. This isn’t accidental, but a deliberate design choice on Apple’s part. Don’t try to bypass such restrictions using Silly Runtime Hacks™. That just opens yourself up to compatibility problems down the pike.

If your app extension needs to get the user’s attention, do that by posting a local notification.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Looking on the bright side of things, you’ve learnt a key compatibility lesson. Sadly, you had to learn that the hard way )-:

The UIApplication object is explicitly marked as unavailable from an app extension. If you add code to an app extension that tries to open a URL in the normal way, using UIApplication.shared.open(_:), it’ll fail to build. You’ve used the Objective-C runtime to bypass that build-time restriction, and that’s now failing.

App extensions are not allowed to open URLs directly. This isn’t accidental, but a deliberate design choice on Apple’s part. Don’t try to bypass such restrictions using Silly Runtime Hacks™. That just opens yourself up to compatibility problems down the pike.

If your app extension needs to get the user’s attention, do that by posting a local notification.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo "If your app extension needs to get the user’s attention, do that by posting a local notification."

In my experience (I've tried it with several) most extension cannot post a notification. If the user grants permission for notifications that is granted to the app, not the extension, that means the extension itself has to request user permission, and that itself isn't possible. Am I missing a trick here?

您好,请问一下,您解决这个问题了吗?

Gregorianst, It’s better if you reply as a reply rather than in the comments. See Quinn’s Top Ten DevForums Tips for more on this.

Is there a way to open main app from the share extension?

No.

It's not possible to send local notification from the extension to the app since the app is in background.

Right. That’s kinda the point. My suggestion was to post a local notification from the app and, if the user taps on it, the system brings the app to the foreground.


In my experience (I've tried it with several) most extension cannot post a notification.

This worked the last time I tried it, but that was a very long time ago.

I also suspect that it’ll vary based on the extension type. I don’t have time today to test this with a share extension, which is the specific extension type that the OP is working on. I’d be interested in hearing up-to-date experience from Tyler_one, or anyone else who can quickly test this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

iOS 18 ShareExtension openURL:
 
 
Q