Browse Source

very basic implementation to inform main app if share extension has attempted to send a message

cyberta 5 years ago
parent
commit
8fb451d08a

+ 3 - 0
DcCore/DcCore/Helper/Constants.swift

@@ -8,4 +8,7 @@ public struct Constants {
         static let deltachatImapPasswordKey = "__DELTACHAT_IMAP_PASSWORD_KEY__"
         static let deltachatImapPasswordKey = "__DELTACHAT_IMAP_PASSWORD_KEY__"
     }
     }
     public static let notificationIdentifier = "deltachat-ios-local-notifications"
     public static let notificationIdentifier = "deltachat-ios-local-notifications"
+
+    public static let sharedUserDefaults = "deltachat-ios-shared-user-defaults"
+    public static let hasExtensionAttemptedToSend = "hasExtensionAttemptedToSend"
 }
 }

+ 2 - 0
DcShare/Controller/ShareViewController.swift

@@ -157,6 +157,8 @@ extension ShareViewController: SendingControllerDelegate {
     func onSendingAttemptFinished() {
     func onSendingAttemptFinished() {
         DispatchQueue.main.async {
         DispatchQueue.main.async {
             self.popConfigurationViewController()
             self.popConfigurationViewController()
+            let userDefaults = UserDefaults(suiteName: Constants.sharedUserDefaults)
+            userDefaults?.set(true, forKey: Constants.hasExtensionAttemptedToSend)
             self.quit()
             self.quit()
         }
         }
     }
     }

+ 20 - 0
deltachat-ios/AppDelegate.swift

@@ -107,6 +107,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         if reachability.connection != .none {
         if reachability.connection != .none {
             self.dcContext.maybeNetwork()
             self.dcContext.maybeNetwork()
         }
         }
+        
+        let userDefaults = UserDefaults.init(suiteName: Constants.sharedUserDefaults)
+        if userDefaults?.bool(forKey: Constants.hasExtensionAttemptedToSend) ?? false {
+            let nc = NotificationCenter.default
+
+            DispatchQueue.main.async {
+                nc.post(
+                    name: dcNotificationChanged,
+                    object: nil,
+                    userInfo: [
+                        //TODO: Use correct message_id and chat_id
+                        "message_id": Int(0),
+                        "chat_id": Int(0),
+                        "date": Date(),
+                    ]
+                )
+            }
+
+            userDefaults?.removeObject(forKey: Constants.hasExtensionAttemptedToSend)
+        }
     }
     }
 
 
     func applicationDidEnterBackground(_: UIApplication) {
     func applicationDidEnterBackground(_: UIApplication) {

+ 3 - 0
deltachat-ios/Helper/Constants.swift

@@ -18,6 +18,9 @@ struct Constants {
 
 
     static let defaultCellHeight: CGFloat = 48
     static let defaultCellHeight: CGFloat = 48
     static let defaultHeaderHeight: CGFloat = 20
     static let defaultHeaderHeight: CGFloat = 20
+
+    public static let sharedUserDefaults = "deltachat-ios-shared-user-defaults"
+    public static let hasExtensionAttemptedToSend = "hasExtensionAttemptedToSend"
 }
 }
 
 
 struct Time {
 struct Time {