You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
381 lines
16 KiB
381 lines
16 KiB
//
|
|
// AppDelegate.swift
|
|
// GMERemittance
|
|
//
|
|
// Created by Fm-user on 11/30/17.
|
|
// Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Firebase
|
|
import FirebaseAuth
|
|
import UserNotifications
|
|
import FirebaseInstanceID
|
|
import FirebaseMessaging
|
|
import BRYXBanner
|
|
import Fabric
|
|
import Crashlytics
|
|
import AlamofireNetworkActivityLogger
|
|
import IQKeyboardManagerSwift
|
|
import LGSideMenuController
|
|
|
|
let isDevelopment = true
|
|
|
|
@UIApplicationMain
|
|
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
|
|
|
|
var window: UIWindow?
|
|
let gcmMessageIDKey = "gcm.message_id"
|
|
var firstTranscationStatusForHome:Bool?
|
|
var firstTranscationStatusForProfileForm:Bool?
|
|
|
|
var cmRegistrationId: String?
|
|
|
|
var notificationSet: Box<Bool?> = Box(nil)
|
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
|
UIApplication.shared.applicationIconBadgeNumber = 0
|
|
firstTranscationStatusForHome = true
|
|
firstTranscationStatusForProfileForm = true
|
|
|
|
NetworkActivityLogger.shared.startLogging()
|
|
NetworkActivityLogger.shared.level = .debug
|
|
IQKeyboardManager.shared.enable = true
|
|
FirebaseApp.configure()
|
|
Fabric.with([Crashlytics.self])
|
|
Messaging.messaging().delegate = self
|
|
registerForNotification(application: application)
|
|
setUUID()
|
|
setupNavBar()
|
|
setupStatusBar()
|
|
setEntryPoint()
|
|
return true
|
|
}
|
|
|
|
private func setUUID() {
|
|
if UserDefaults.standard.string(forKey: AppConstants.uuid) == nil {
|
|
let uuid = UUID().uuidString
|
|
UserDefaults.standard.set(uuid, forKey: AppConstants.uuid)
|
|
}
|
|
}
|
|
|
|
private func setupStatusBar() {
|
|
// let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
|
|
// if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
|
|
// statusBar.backgroundColor = UIColor.blue
|
|
// }
|
|
}
|
|
|
|
private func setupNavBar() {
|
|
let appearance = UINavigationBar.appearance()
|
|
appearance.backIndicatorImage = #imageLiteral(resourceName: "backIconBlack")
|
|
appearance.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "backIconBlack")
|
|
appearance.tintColor = UIColor.black
|
|
}
|
|
|
|
private func setEntryPoint() {
|
|
let _default = UserDefaults.standard
|
|
if let loginStatus = _default.string(forKey: UserKeys.accessCode) {
|
|
// user is logged in
|
|
|
|
let mainWireFrame = MainWireframe.shared
|
|
// self.window?.rootViewController =
|
|
let tabBarViewController = mainWireFrame?.getMainView()
|
|
|
|
let sidemenuVc = UIStoryboard(name: "SideMenu", bundle: nil).instantiateViewController(withIdentifier: "SideMenuViewController") as! SideMenuViewController
|
|
//
|
|
let sideMenuController = LGSideMenuController(rootViewController: tabBarViewController, leftViewController: sidemenuVc, rightViewController: nil)
|
|
//
|
|
|
|
sideMenuController.rootViewLayerShadowColor = UIColor(white: 0.9, alpha: 0.6)
|
|
sideMenuController.rootViewLayerShadowRadius = 8.0
|
|
sideMenuController.leftViewPresentationStyle = .scaleFromBig
|
|
sideMenuController.leftViewWidth = UIScreen.main.bounds.width - 70.0
|
|
sideMenuController.leftViewBackgroundBlurEffect = UIBlurEffect(style: .regular)
|
|
|
|
window?.backgroundColor = sidemenuVc.view.backgroundColor
|
|
self.window?.rootViewController = sideMenuController
|
|
|
|
|
|
|
|
}else {
|
|
// go to splashscreen
|
|
let splashWireframe = SplashScreenWireframe()
|
|
let nav = UINavigationController.init(rootViewController: splashWireframe.getMainView())
|
|
self.window?.rootViewController = nav
|
|
}
|
|
}
|
|
|
|
private func registerForNotification(application: UIApplication) {
|
|
if #available(iOS 10.0, *) {
|
|
// For iOS 10 display notification (sent via APNS)
|
|
UNUserNotificationCenter.current().delegate = self
|
|
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
|
|
UNUserNotificationCenter.current().requestAuthorization(
|
|
options: authOptions,
|
|
completionHandler: {_, _ in })
|
|
} else {
|
|
let settings: UIUserNotificationSettings =
|
|
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
|
|
application.registerUserNotificationSettings(settings)
|
|
}
|
|
|
|
application.registerForRemoteNotifications()
|
|
}
|
|
|
|
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
|
|
// If you are receiving a notification message while your app is in the background,
|
|
// this callback will not be fired till the user taps on the notification launching the application.
|
|
// TODO: Handle data of notification
|
|
// With swizzling disabled you must let Messaging know about the message, for Analytics
|
|
// Messaging.messaging().appDidReceiveMessage(userInfo)
|
|
// Print message ID.
|
|
if userInfo[gcmMessageIDKey] != nil {
|
|
// print(" message: \(messageID)")
|
|
}
|
|
// Print full message.
|
|
// print("fore ground ", userInfo)
|
|
}
|
|
|
|
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
|
|
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
|
// If you are receiving a notification message while your app is in the background,
|
|
// this callback will not be fired till the user taps on the notification launching the application.
|
|
// TODO: Handle data of notification
|
|
// With swizzling disabled you must let Messaging know about the message, for Analytics
|
|
// Messaging.messaging().appDidReceiveMessage(userInfo)
|
|
// Print message ID.
|
|
if userInfo[gcmMessageIDKey] != nil {
|
|
// print("Message ID completionHandler: \(messageID)")
|
|
}
|
|
|
|
// Print full message.
|
|
// print(userInfo)
|
|
/**
|
|
redirection of page after background push notification
|
|
*/
|
|
if
|
|
let aps = userInfo["aps"] as? NSDictionary,
|
|
let alert = aps["alert"] as? NSDictionary,
|
|
let _ = alert["body"] as? String,
|
|
let _ = alert["title"] as? String {
|
|
let codeID = userInfo["code"] as? String
|
|
self.redirectWithPushNotification(notificationCode: codeID!)
|
|
}
|
|
|
|
completionHandler(UIBackgroundFetchResult.newData)
|
|
}
|
|
|
|
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
|
|
cmRegistrationId = fcmToken
|
|
notificationSet.value = true
|
|
print(fcmToken)
|
|
}
|
|
|
|
|
|
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
|
|
print(remoteMessage.appData)
|
|
}
|
|
|
|
public func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
|
|
|
|
}
|
|
|
|
@available(iOS 10.0, *)
|
|
func userNotificationCenter(_ center: UNUserNotificationCenter,
|
|
willPresent notification: UNNotification,
|
|
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
var userInfo = notification.request.content.userInfo
|
|
|
|
if userInfo[gcmMessageIDKey] != nil {
|
|
// print("Message ID: def \(messageID)")
|
|
}
|
|
|
|
/**
|
|
redirection of page after foreground push notification
|
|
*/
|
|
|
|
if
|
|
let aps = userInfo["aps"] as? NSDictionary,
|
|
let alert = aps["alert"] as? NSDictionary,
|
|
let body = alert["body"] as? String,
|
|
let title = alert["title"] as? String {
|
|
// print("Title: \(title) \nBody:\(body)")
|
|
let codeID = userInfo["code"] as? String
|
|
|
|
let banner = Banner(title: title, subtitle: body, image: #imageLiteral(resourceName: "ic_gme"), backgroundColor: UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0))
|
|
banner.didTapBlock = {
|
|
// print("Banner was tapped on \(Date())!")
|
|
self.redirectWithPushNotification(notificationCode: codeID!)
|
|
}
|
|
|
|
banner.show(duration: 5.0)
|
|
}
|
|
|
|
if userInfo["code"] != nil {
|
|
// print("codeAP delegate: \(codeID)")
|
|
}
|
|
|
|
// Change this to your preferred presentation option
|
|
completionHandler([])
|
|
}
|
|
|
|
|
|
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
|
// print("Unable to register for remote notifications: \(error.localizedDescription)")
|
|
}
|
|
|
|
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
|
|
}
|
|
|
|
/**
|
|
method for redirection of page when push notification tap
|
|
*/
|
|
|
|
func redirectWithPushNotification(notificationCode: String){
|
|
let nav = UINavigationController()
|
|
|
|
switch notificationCode {
|
|
|
|
case "500":
|
|
|
|
InviteViewController.notificationCode = "p500"
|
|
|
|
let storyboard = UIStoryboard(name: "Invite", bundle: nil)
|
|
let viewController = storyboard.instantiateViewController(withIdentifier :"InviteViewController") as! InviteViewController
|
|
let navController = UINavigationController.init(rootViewController: viewController)
|
|
|
|
if let window = self.window, let rootViewController = window.rootViewController {
|
|
var currentController = rootViewController
|
|
while let presentedController = currentController.presentedViewController {
|
|
currentController = presentedController
|
|
}
|
|
currentController.present(navController, animated: true, completion: nil)
|
|
}
|
|
|
|
case "200":
|
|
|
|
TranscationStatementViewController.notificationCode = "p200"
|
|
let storyboard = UIStoryboard.init(name: "TransactionStatement", bundle: Bundle.main)
|
|
if let transcationStatementViewController = storyboard.instantiateViewController(withIdentifier: "TranscationStatementViewController") as? TranscationStatementViewController {
|
|
|
|
nav.viewControllers = [transcationStatementViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
|
|
case "201":
|
|
|
|
MoneyRequestViewController.notificationCode = "p201"
|
|
let storyboard = UIStoryboard.init(name: "WalletTransfer", bundle: Bundle.main)
|
|
if let moneyRequestViewController = storyboard.instantiateViewController(withIdentifier: "MoneyRequestViewController") as? MoneyRequestViewController {
|
|
|
|
nav.viewControllers = [moneyRequestViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
|
|
case "202":
|
|
|
|
// redirectViewController(storyBoardName: "WalletTransfer", identifier: "WalletTransactionListViewController")
|
|
WalletTransactionListViewController.notificationCode = "p202"
|
|
let storyboard = UIStoryboard.init(name: "WalletTransfer", bundle: Bundle.main)
|
|
if let walletTransactionListViewController = storyboard.instantiateViewController(withIdentifier: "WalletTransactionListViewController") as? WalletTransactionListViewController {
|
|
walletTransactionListViewController.walletStatus = "walletBorrow"
|
|
|
|
nav.viewControllers = [walletTransactionListViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
|
|
case "203":
|
|
|
|
TranscationStatementViewController.notificationCode = "p203"
|
|
let storyboard = UIStoryboard.init(name: "TransactionStatement", bundle: Bundle.main)
|
|
if let transcationStatementViewController = storyboard.instantiateViewController(withIdentifier: "TranscationStatementViewController") as? TranscationStatementViewController {
|
|
|
|
nav.viewControllers = [transcationStatementViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
|
|
case "204":
|
|
|
|
TranscationStatementViewController.notificationCode = "p204"
|
|
let storyboard = UIStoryboard.init(name: "TransactionStatement", bundle: Bundle.main)
|
|
if let transcationStatementViewController = storyboard.instantiateViewController(withIdentifier: "TranscationStatementViewController") as? TranscationStatementViewController {
|
|
|
|
nav.viewControllers = [transcationStatementViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
|
|
case "205":
|
|
|
|
// redirectViewController(storyBoardName: "WalletTransfer", identifier: "walletViewController")
|
|
WalletTransactionListViewController.notificationCode = "p205"
|
|
let storyboard = UIStoryboard.init(name: "WalletTransfer", bundle: Bundle.main)
|
|
if let walletTransactionListViewController = storyboard.instantiateViewController(withIdentifier: "WalletTransactionListViewController") as? WalletTransactionListViewController {
|
|
walletTransactionListViewController.walletStatus = "walletTransfer"
|
|
nav.viewControllers = [walletTransactionListViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
|
|
|
|
case "206":
|
|
|
|
TranscationStatementViewController.notificationCode = "p200"
|
|
let storyboard = UIStoryboard.init(name: "TransactionStatement", bundle: Bundle.main)
|
|
if let transcationStatementViewController = storyboard.instantiateViewController(withIdentifier: "TranscationStatementViewController") as? TranscationStatementViewController {
|
|
|
|
nav.viewControllers = [transcationStatementViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
case "207":
|
|
|
|
TranscationStatementViewController.notificationCode = "p200"
|
|
let storyboard = UIStoryboard.init(name: "TransactionStatement", bundle: Bundle.main)
|
|
if let transcationStatementViewController = storyboard.instantiateViewController(withIdentifier: "TranscationStatementViewController") as? TranscationStatementViewController {
|
|
|
|
nav.viewControllers = [transcationStatementViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
case "208":
|
|
|
|
TranscationStatementViewController.notificationCode = "p208"
|
|
let storyboard = UIStoryboard.init(name: "TransactionStatement", bundle: Bundle.main)
|
|
if let transcationStatementViewController = storyboard.instantiateViewController(withIdentifier: "TranscationStatementViewController") as? TranscationStatementViewController {
|
|
|
|
nav.viewControllers = [transcationStatementViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
case "700":
|
|
|
|
// redirectViewController(storyBoardName: "Reward", identifier: "RewardViewController")
|
|
RewardViewController.notificationCode = "p700"
|
|
let storyboard = UIStoryboard.init(name: "Reward", bundle: Bundle.main)
|
|
if let rewardViewController = storyboard.instantiateViewController(withIdentifier: "RewardViewController") as? RewardViewController {
|
|
|
|
nav.viewControllers = [rewardViewController]
|
|
|
|
window?.rootViewController = nav
|
|
}
|
|
|
|
case "750":
|
|
return
|
|
//redirectViewController(storyBoardName: "Home", identifier: "CommentsViewController")
|
|
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|