From b74ed615a87aacd6f7f9c50b2a25f3e4cfb8e118 Mon Sep 17 00:00:00 2001 From: Rafael Kellermann Streit Date: Wed, 10 May 2017 08:47:24 -0300 Subject: [PATCH 1/3] Adjust notification settings and clean all --- Rocket.Chat.xcodeproj/project.pbxproj | 4 ++-- Rocket.Chat/AppDelegate.swift | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Rocket.Chat.xcodeproj/project.pbxproj b/Rocket.Chat.xcodeproj/project.pbxproj index dbb68bcdeb..b55ea8a1d4 100644 --- a/Rocket.Chat.xcodeproj/project.pbxproj +++ b/Rocket.Chat.xcodeproj/project.pbxproj @@ -1541,7 +1541,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEVELOPMENT_TEAM = S6UPZG7ZR3; INFOPLIST_FILE = Rocket.Chat/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = chat.rocket.ios; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1562,7 +1562,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEVELOPMENT_TEAM = S6UPZG7ZR3; INFOPLIST_FILE = Rocket.Chat/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = chat.rocket.ios; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Rocket.Chat/AppDelegate.swift b/Rocket.Chat/AppDelegate.swift index fc0de3ed42..01dfb81ffd 100644 --- a/Rocket.Chat/AppDelegate.swift +++ b/Rocket.Chat/AppDelegate.swift @@ -8,6 +8,7 @@ import UIKit import RealmSwift +import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -17,7 +18,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { Launcher().prepareToLaunch(with: launchOptions) - application.registerUserNotificationSettings(UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)) + UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (_, _) in } application.registerForRemoteNotifications() return true @@ -25,6 +26,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: AppDelegate LifeCycle + func applicationDidBecomeActive(_ application: UIApplication) { + let center = UNUserNotificationCenter.current() + center.removeAllDeliveredNotifications() + } + func applicationDidEnterBackground(_ application: UIApplication) { if AuthManager.isAuthenticated() != nil { UserManager.setUserPresence(status: .away) { (_) in @@ -43,10 +49,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: Remote Notification - func application(_ application: UIApplication, didReceive notification: UILocalNotification) { - Log.debug("Notification: \(notification)") - } - func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { Log.debug("Notification: \(userInfo)") } From 81b2130313131ed536b9e3090d9ccbb036ff1864 Mon Sep 17 00:00:00 2001 From: Rafael Kellermann Streit Date: Wed, 10 May 2017 09:19:58 -0300 Subject: [PATCH 2/3] Update badge with all unread --- .../Subscriptions/SubscriptionsViewController.swift | 1 + Rocket.Chat/Managers/Model/SubscriptionManager.swift | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/Rocket.Chat/Controllers/Subscriptions/SubscriptionsViewController.swift b/Rocket.Chat/Controllers/Subscriptions/SubscriptionsViewController.swift index d66ce31b80..6c55beb7d0 100644 --- a/Rocket.Chat/Controllers/Subscriptions/SubscriptionsViewController.swift +++ b/Rocket.Chat/Controllers/Subscriptions/SubscriptionsViewController.swift @@ -170,6 +170,7 @@ extension SubscriptionsViewController { subscriptions = auth.subscriptions.sorted(byKeyPath: "lastSeen", ascending: false) groupSubscription() updateCurrentUserInformation() + SubscriptionManager.updateUnreadApplicationBadge() tableView?.reloadData() } diff --git a/Rocket.Chat/Managers/Model/SubscriptionManager.swift b/Rocket.Chat/Managers/Model/SubscriptionManager.swift index b979b8e194..62e95e9c0e 100644 --- a/Rocket.Chat/Managers/Model/SubscriptionManager.swift +++ b/Rocket.Chat/Managers/Model/SubscriptionManager.swift @@ -11,6 +11,18 @@ import RealmSwift struct SubscriptionManager { + static func updateUnreadApplicationBadge() { + var unread = 0 + + Realm.execute({ (realm) in + for obj in realm.objects(Subscription.self) { + unread += obj.unread + } + }, completion: { + UIApplication.shared.applicationIconBadgeNumber = unread + }) + } + // swiftlint:disable function_body_length static func updateSubscriptions(_ auth: Auth, completion: @escaping MessageCompletion) { var params: [[String: Any]] = [] From 7e68ade672ef1879f324fa47936ee68d091a7aa0 Mon Sep 17 00:00:00 2001 From: Rafael Kellermann Streit Date: Wed, 10 May 2017 10:41:38 -0300 Subject: [PATCH 3/3] Adjust target deployment to iOS 10 --- Podfile | 2 +- Podfile.lock | 2 +- Rocket.Chat.xcodeproj/project.pbxproj | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Podfile b/Podfile index 6b2a85d267..90e116174d 100644 --- a/Podfile +++ b/Podfile @@ -1,6 +1,6 @@ source 'https://github.com/CocoaPods/Specs.git' -platform :ios, '9.0' +platform :ios, '10.0' use_frameworks! def shared_pods diff --git a/Podfile.lock b/Podfile.lock index aae9b356db..cc3477eddf 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -104,6 +104,6 @@ SPEC CHECKSUMS: TSMarkdownParser: 114779f14d46e7fc6d9880d4797e5abcc01f92c3 URBMediaFocusViewController: 26779e301fe75ec0152fbe8b476bd06ccee9f9b3 -PODFILE CHECKSUM: 08c486ad1a09fa2a611b6c59c154048f4a82e16d +PODFILE CHECKSUM: f616230e4b79b25b8a4e0f0f93067849361aafc5 COCOAPODS: 1.2.1 diff --git a/Rocket.Chat.xcodeproj/project.pbxproj b/Rocket.Chat.xcodeproj/project.pbxproj index b55ea8a1d4..02d4f80047 100644 --- a/Rocket.Chat.xcodeproj/project.pbxproj +++ b/Rocket.Chat.xcodeproj/project.pbxproj @@ -1581,6 +1581,7 @@ DEVELOPMENT_TEAM = S6UPZG7ZR3; ENABLE_BITCODE = YES; INFOPLIST_FILE = Rocket.ChatTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "chat.rocket.Rocket-ChatTests"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1599,6 +1600,7 @@ DEVELOPMENT_TEAM = S6UPZG7ZR3; ENABLE_BITCODE = YES; INFOPLIST_FILE = Rocket.ChatTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "chat.rocket.Rocket-ChatTests"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1613,6 +1615,7 @@ buildSettings = { DEVELOPMENT_TEAM = S6UPZG7ZR3; INFOPLIST_FILE = Rocket.ChatUITests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "chat.rocket.Rocket-ChatUITests"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1626,6 +1629,7 @@ buildSettings = { DEVELOPMENT_TEAM = S6UPZG7ZR3; INFOPLIST_FILE = Rocket.ChatUITests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "chat.rocket.Rocket-ChatUITests"; PRODUCT_NAME = "$(TARGET_NAME)";