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")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.developer.mail-client</key>
|
||||
<true/>
|
||||
<key>AppGroupId</key>
|
||||
<string>${APP_GROUP_ID}</string>
|
||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||
@@ -33,6 +35,7 @@
|
||||
<array>
|
||||
<string>ShareMedia-$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<string>teammail.mobile</string>
|
||||
<string>mailto</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
|
||||
Reference in New Issue
Block a user