fixed stale state after logout and replayed or lost share intents
This commit is contained in:
@@ -13,21 +13,44 @@ class SceneDelegate: FlutterSceneDelegate {
|
||||
options connectionOptions: UIScene.ConnectionOptions
|
||||
) {
|
||||
super.scene(scene, willConnectTo: session, options: connectionOptions)
|
||||
for context in connectionOptions.urlContexts {
|
||||
var handledShare = false
|
||||
for context in connectionOptions.urlContexts where isShareUrl(context.url) {
|
||||
_ = ReceiveSharingIntentPlugin.instance.application(
|
||||
UIApplication.shared,
|
||||
didFinishLaunchingWithOptions: [UIApplication.LaunchOptionsKey.url: context.url]
|
||||
)
|
||||
handledShare = true
|
||||
}
|
||||
if handledShare { clearSharedPayload() }
|
||||
}
|
||||
|
||||
override func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
|
||||
for context in URLContexts {
|
||||
let shares = URLContexts.filter { isShareUrl($0.url) }
|
||||
for context in shares {
|
||||
_ = ReceiveSharingIntentPlugin.instance.application(
|
||||
UIApplication.shared,
|
||||
open: context.url,
|
||||
options: [:]
|
||||
)
|
||||
}
|
||||
if !shares.isEmpty { clearSharedPayload() }
|
||||
let others = URLContexts.subtracting(shares)
|
||||
if !others.isEmpty { super.scene(scene, openURLContexts: others) }
|
||||
}
|
||||
|
||||
private func isShareUrl(_ url: URL) -> Bool {
|
||||
ReceiveSharingIntentPlugin.instance.hasMatchingSchemePrefix(url: url)
|
||||
}
|
||||
|
||||
// The plugin keeps the payload in memory once read but never removes it
|
||||
// from the App Group defaults. The Share Extension opens the app twice per
|
||||
// share and a scene reconnect replays the URL, so every later delivery
|
||||
// would publish the finished share again.
|
||||
private func clearSharedPayload() {
|
||||
let groupId = Bundle.main.object(forInfoDictionaryKey: "AppGroupId") as? String
|
||||
let defaults = UserDefaults(
|
||||
suiteName: groupId ?? "group.\(Bundle.main.bundleIdentifier ?? "")")
|
||||
defaults?.removeObject(forKey: "ShareKey")
|
||||
defaults?.removeObject(forKey: "ShareMessageKey")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user