alqindiirsyam 1 жил өмнө
parent
commit
2aad9f123d

+ 4 - 0
appbuilder-ios/DigiXLite/DigiXLite/Info.plist

@@ -37,6 +37,10 @@
     <key>LSApplicationQueriesSchemes</key>
     <key>LSApplicationQueriesSchemes</key>
     <array>
     <array>
          <string>whatsapp</string>
          <string>whatsapp</string>
+         <string>googlegmail</string>
+         <string>ms-outlook</string>
+         <string>readdle-spark</string>
+         <string>ymail</string>
     </array>
     </array>
 	<key>UIAppFonts</key>
 	<key>UIAppFonts</key>
 	<array>
 	<array>

+ 4 - 0
appbuilder-ios/DigiXLite/DigiXLite/Source/APIS.swift

@@ -698,6 +698,10 @@ public class APIS: NSObject {
             }
             }
         }
         }
     }
     }
+    
+    public static func openMail() {
+        DigiX.openmailAction()
+    }
 }
 }
 
 
 extension UINavigationController {
 extension UINavigationController {

+ 28 - 0
appbuilder-ios/DigiXLite/DigiXLite/Source/DigiX.swift

@@ -821,6 +821,34 @@ public class DigiX: NSObject {
         }
         }
     }
     }
     
     
+    static func openmailAction(subject: String = "", body: String = "", to: String = "") {
+        let subjectEncoded = subject.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
+        let bodyEncoded = body.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
+        let toEmail = to
+        
+        let gmailUrl = URL(string: "googlegmail://co?to=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        let outlookUrl = URL(string: "ms-outlook://compose?to=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        let yahooMail = URL(string: "ymail://mail/compose?to=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        let sparkUrl = URL(string: "readdle-spark://compose?recipient=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        let defaultUrl = URL(string: "mailto:\(toEmail)?subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        
+        if UIApplication.shared.canOpenURL(gmailUrl as URL) {
+            openMail(gmailUrl)
+        } else if UIApplication.shared.canOpenURL(outlookUrl as URL) {
+            openMail(outlookUrl)
+        } else if UIApplication.shared.canOpenURL(yahooMail as URL) {
+            openMail(yahooMail)
+        } else if UIApplication.shared.canOpenURL(sparkUrl as URL) {
+            openMail(sparkUrl)
+        } else if UIApplication.shared.canOpenURL(defaultUrl as URL) {
+            openMail(defaultUrl)
+        }
+    }
+    
+    private static func openMail(_ url: URL) {
+        UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
+    }
+    
     static var alertChangeProfile = LibAlertController()
     static var alertChangeProfile = LibAlertController()
     public static func checkIsChangePerson() -> Bool {
     public static func checkIsChangePerson() -> Bool {
         let isChangeProfile = Utils.getSetProfile()
         let isChangeProfile = Utils.getSetProfile()

+ 21 - 13
appbuilder-ios/NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -822,23 +822,31 @@ public class Nexilis: NSObject {
         }
         }
     }
     }
     
     
-    static func openmailAction() {
-        if let googleUrl = NSURL(string: "googlegmail://"), UIApplication.shared.canOpenURL(googleUrl as URL) {
-            openMail(googleUrl)
-        } else if let mailURL = NSURL(string: "message://"), UIApplication.shared.canOpenURL(mailURL as URL) {
-            openMail(mailURL)
-        } else if let outlookURL = NSURL(string: "ms-outlook://"), UIApplication.shared.canOpenURL(outlookURL as URL) {
-            openMail(outlookURL)
-        } else if let yahooURL = NSURL(string: "ymail://"), UIApplication.shared.canOpenURL(yahooURL as URL) {
-            openMail(yahooURL)
-        } else if let sparkUrl = NSURL(string: "readdle-spark://"), UIApplication.shared.canOpenURL(sparkUrl as URL) {
+    static func openmailAction(subject: String = "", body: String = "", to: String = "") {
+        let subjectEncoded = subject.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
+        let bodyEncoded = body.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
+        let toEmail = to
+        
+        let gmailUrl = URL(string: "googlegmail://co?to=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        let outlookUrl = URL(string: "ms-outlook://compose?to=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        let yahooMail = URL(string: "ymail://mail/compose?to=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        let sparkUrl = URL(string: "readdle-spark://compose?recipient=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        let defaultUrl = URL(string: "mailto:\(toEmail)?subject=\(subjectEncoded)&body=\(bodyEncoded)")!
+        
+        if UIApplication.shared.canOpenURL(gmailUrl as URL) {
+            openMail(gmailUrl)
+        } else if UIApplication.shared.canOpenURL(outlookUrl as URL) {
+            openMail(outlookUrl)
+        } else if UIApplication.shared.canOpenURL(yahooMail as URL) {
+            openMail(yahooMail)
+        } else if UIApplication.shared.canOpenURL(sparkUrl as URL) {
             openMail(sparkUrl)
             openMail(sparkUrl)
-        } else {
-            // showAlert
+        } else if UIApplication.shared.canOpenURL(defaultUrl as URL) {
+            openMail(defaultUrl)
         }
         }
     }
     }
     
     
-    private static func openMail(_ url: NSURL) {
+    private static func openMail(_ url: URL) {
         UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
         UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
     }
     }