TF-501 [iOS] add Mail app to be Default mail
This commit is contained in:
@@ -15,6 +15,18 @@ import receive_sharing_intent
|
||||
FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!)
|
||||
}
|
||||
}
|
||||
|
||||
let sharingIntent = SwiftReceiveSharingIntentPlugin.instance
|
||||
if let url = launchOptions?[UIApplication.LaunchOptionsKey.url] as? URL {
|
||||
if url.scheme == "mailto" {
|
||||
if let url = handleEmailAndress(open: url) {
|
||||
let corrected = launchOptions!.map { (key, value) in key != .url ? (key, value) : (key, url) }
|
||||
|
||||
return sharingIntent.application(application, didFinishLaunchingWithOptions: Dictionary(uniqueKeysWithValues: corrected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||
}
|
||||
|
||||
@@ -24,6 +36,11 @@ import receive_sharing_intent
|
||||
return sharingIntent.application(app, open: url, options: options)
|
||||
}
|
||||
|
||||
if url.scheme == "mailto" {
|
||||
if let url = handleEmailAndress(open: url) {
|
||||
return sharingIntent.application(app, open: url, options: options)
|
||||
}
|
||||
}
|
||||
// For example load MSALPublicClientApplication
|
||||
// return MSALPublicClientApplication.handleMSALResponse(url, sourceApplication: options[.sourceApplication] as? String)
|
||||
|
||||
@@ -34,4 +51,18 @@ import receive_sharing_intent
|
||||
return super.application(app, open: url, options:options)
|
||||
}
|
||||
|
||||
private func handleEmailAndress(open url: URL) -> URL? {
|
||||
let appDomain = Bundle.main.bundleIdentifier!
|
||||
let appGroupId = (Bundle.main.object(forInfoDictionaryKey: "AppGroupId") as? String) ?? "group.\(Bundle.main.bundleIdentifier!)"
|
||||
let sharedKey = "ShareKey"
|
||||
var sharedText: [String] = []
|
||||
if let email = url.absoluteString.components(separatedBy: ":").last {
|
||||
sharedText.append(email)
|
||||
}
|
||||
let userDefaults = UserDefaults(suiteName: appGroupId)
|
||||
userDefaults?.set(sharedText, forKey: sharedKey)
|
||||
userDefaults?.synchronize()
|
||||
return URL(string: "ShareMedia-\(appDomain)://dataUrl=\(sharedKey)#text")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user