|
@@ -198,11 +198,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
tMessage.mBodies[CoreMessage_TMessageKey.KEY] = key
|
|
|
return tMessage
|
|
|
}
|
|
|
+
|
|
|
+ private func registerForPushNotifications() {
|
|
|
+ if #available(iOS 10.0, *) {
|
|
|
+ let center = UNUserNotificationCenter.current()
|
|
|
+ center.delegate = self
|
|
|
+ center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
|
|
|
+ if error == nil{
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ UIApplication.shared.registerForRemoteNotifications()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
|
|
|
+ UIApplication.shared.registerForRemoteNotifications()
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
-extension AppDelegate: ConnectDelegate {
|
|
|
+extension AppDelegate: ConnectDelegate, UNUserNotificationCenterDelegate {
|
|
|
|
|
|
func onSuccess(userId: String) {
|
|
|
print(#function, "userId: \(userId)")
|
|
@@ -212,5 +230,90 @@ extension AppDelegate: ConnectDelegate {
|
|
|
print(#function, "error: \(error)")
|
|
|
}
|
|
|
|
|
|
+ func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
|
+ let deviceTokenString = deviceToken.map { String(format: "%02x", $0) }.joined()
|
|
|
+ print("TOKEN: \(deviceTokenString)")
|
|
|
+ }
|
|
|
+
|
|
|
+ func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
|
|
+ print(error)
|
|
|
+ }
|
|
|
+
|
|
|
+ func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
|
+ let userInfo = response.notification.request.content.userInfo
|
|
|
+ if let opposite = userInfo["opposite"] as? String {
|
|
|
+ let user = User.getDataCanNil(pin: opposite)
|
|
|
+ if user != nil {
|
|
|
+ openEditorPersonal(opposite: opposite)
|
|
|
+ } else {
|
|
|
+ let group = Group.getData(group_id: opposite)
|
|
|
+ let topic = Topic.getData(topic_id: opposite)
|
|
|
+ if group != nil || topic != nil {
|
|
|
+ openEditorGroup(opposite: opposite)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UIApplication.shared.applicationIconBadgeNumber = 0
|
|
|
+ UNUserNotificationCenter.current().removeAllDeliveredNotifications()
|
|
|
+ completionHandler()
|
|
|
+ }
|
|
|
+
|
|
|
+ func openEditorPersonal(opposite: String) {
|
|
|
+ let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
|
|
|
+ editorPersonalVC.hidesBottomBarWhenPushed = true
|
|
|
+ editorPersonalVC.unique_l_pin = opposite
|
|
|
+ editorPersonalVC.fromNotification = true
|
|
|
+ let onGoingCC = UserDefaults.standard.string(forKey: "onGoingCC") ?? ""
|
|
|
+ if !onGoingCC.isEmpty {
|
|
|
+ let compalintId = onGoingCC.components(separatedBy: ",")[2]
|
|
|
+ let fPinCC = onGoingCC.isEmpty ? "" : onGoingCC.components(separatedBy: ",")[1]
|
|
|
+ editorPersonalVC.isContactCenter = true
|
|
|
+ editorPersonalVC.fPinContacCenter = fPinCC
|
|
|
+ editorPersonalVC.complaintId = compalintId
|
|
|
+ editorPersonalVC.onGoingCC = true
|
|
|
+ editorPersonalVC.isRequestContactCenter = false
|
|
|
+ }
|
|
|
+ let navigationController = UINavigationController(rootViewController: editorPersonalVC)
|
|
|
+ navigationController.modalPresentationStyle = .fullScreen
|
|
|
+ navigationController.navigationBar.tintColor = .white
|
|
|
+ navigationController.navigationBar.barTintColor = .mainColor
|
|
|
+ navigationController.navigationBar.isTranslucent = false
|
|
|
+ navigationController.navigationBar.overrideUserInterfaceStyle = .dark
|
|
|
+ navigationController.navigationBar.barStyle = .black
|
|
|
+ let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white]
|
|
|
+ UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
|
|
|
+ let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
|
|
|
+ navigationController.navigationBar.titleTextAttributes = textAttributes
|
|
|
+ navigationController.view.backgroundColor = .mainColor
|
|
|
+ if UIApplication.shared.visibleViewController?.navigationController != nil {
|
|
|
+ UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
|
|
|
+ } else {
|
|
|
+ UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func openEditorGroup(opposite: String) {
|
|
|
+ let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "editorGroupVC") as! EditorGroup
|
|
|
+ editorGroupVC.hidesBottomBarWhenPushed = true
|
|
|
+ editorGroupVC.unique_l_pin = opposite
|
|
|
+ editorGroupVC.fromNotification = true
|
|
|
+ let navigationController = UINavigationController(rootViewController: editorGroupVC)
|
|
|
+ navigationController.modalPresentationStyle = .fullScreen
|
|
|
+ navigationController.navigationBar.tintColor = .white
|
|
|
+ navigationController.navigationBar.barTintColor = .mainColor
|
|
|
+ navigationController.navigationBar.isTranslucent = false
|
|
|
+ navigationController.navigationBar.overrideUserInterfaceStyle = .dark
|
|
|
+ navigationController.navigationBar.barStyle = .black
|
|
|
+ let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white]
|
|
|
+ UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
|
|
|
+ let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
|
|
|
+ navigationController.navigationBar.titleTextAttributes = textAttributes
|
|
|
+ navigationController.view.backgroundColor = .mainColor
|
|
|
+ if UIApplication.shared.visibleViewController?.navigationController != nil {
|
|
|
+ UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
|
|
|
+ } else {
|
|
|
+ UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|