Browse Source

refractored the fcm token code

pull/1/head
gme_2 6 years ago
parent
commit
99e14ba801
  1. 138
      GMERemittance/AppDelegate.swift
  2. 34
      GMERemittance/Model/RegisterRequestModel.swift
  3. 25
      GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractor.swift
  4. 12
      GMERemittance/Module/Register/Application Logic/Service/RegisterServiceType.swift

138
GMERemittance/AppDelegate.swift

@ -35,35 +35,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
firstTranscationStatusForHome = true
firstTranscationStatusForProfileForm = true
// Override point for customization after application launch.
// [START set_messaging_delegate]
Messaging.messaging().delegate = self
// [END set_messaging_delegate]
// Register for remote notifications. This shows a permission dialog on first run, to
// show the dialog at a more appropriate time move this registration accordingly.
// [START register_for_notifications]
NetworkActivityLogger.shared.startLogging()
NetworkActivityLogger.shared.level = .debug
IQKeyboardManager.shared.enable = true
registerForNotification(application: application)
FirebaseApp.configure()
Fabric.with([Crashlytics.self])
Messaging.messaging().delegate = self
registerForNotification(application: application)
setUUID()
setupNavBar()
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)
}
setupNavBar()
setEntryPoint()
// if (UserDefaults.standard.object(forKey: "com.gmeremit.loginStatus")) != nil{
// redirectToApp()
// }
//
return true
}
private func setupNavBar() {
@ -150,19 +139,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
// print("Firebase registration token: \(fcmToken)")
cmRegistrationId = fcmToken
notificationSet.value = true
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
print(fcmToken)
}
// [END refresh_token]
// [START ios_10_data_message]
// Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
// To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true.
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
// print("Received data message: \(remoteMessage.appData)")
print(remoteMessage.appData)
}
public func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
@ -175,9 +159,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
var userInfo = notification.request.content.userInfo
// 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: def \(messageID)")
}
@ -216,83 +197,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
// print("Unable to register for remote notifications: \(error.localizedDescription)")
}
// This function is added here only for debugging purposes, and can be removed if swizzling is enabled.
// If swizzling is disabled then this function must be implemented so that the APNs token can be paired to
// the FCM registration token.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// print("APNs token retrieved: \(deviceToken)")
// With swizzling disabled you must set the APNs token here.
// Messaging.messaging().apnsToken = deviceToken
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// print("App terminate")
}
/**
redirection to home page if user is already login to app otherwise redirect to KYC form.
*/
func redirectToApp() {
let nav = UINavigationController()
if (UserDefaults.standard.object(forKey: "com.gmeremit.loginStatus") as! Bool) {
// login cha
guard (UserDefaults.standard.object(forKey: UserKeys.kyc) as? Bool) ?? false == true else {
let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
if let KYCPersonalInfoViewController = storyboard.instantiateViewController(withIdentifier: "KYCPersonalInfoViewController") as? KYCPersonalInfoViewController {
nav.viewControllers = [KYCPersonalInfoViewController]
window?.rootViewController = nav
}
return
}
let mainWireFrame = MainWireframe.shared
let tabbarViewController = mainWireFrame?.getMainView()
window?.rootViewController = tabbarViewController
window?.makeKeyAndVisible()
// let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
// if let tabViewController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as? UITabBarController {
//
// nav.viewControllers = [tabViewController]
//
// window?.rootViewController = nav
// }
} else {
let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
if let splashScreenViewController = storyboard.instantiateViewController(withIdentifier: "SplashScreenViewController") as? SplashScreenViewController {
// nav.viewControllers = [splashScreenViewController]
window?.rootViewController = splashScreenViewController
}
}
}
/**
@ -445,23 +351,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
//extension AppDelegate : MessagingDelegate {
// // [START refresh_token]
// func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
// print("Firebase registration token: \(fcmToken)")
//
// // TODO: If necessary send token to application server.
// // Note: This callback is fired at each app startup and whenever a new token is generated.
// }
// // [END refresh_token]
// // [START ios_10_data_message]
// // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
// // To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true.
// func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
// print("Received data message: \(remoteMessage.appData)")
// }
// // [END ios_10_data_message]
//}

34
GMERemittance/Model/RegisterRequestModel.swift

@ -9,7 +9,14 @@
import Foundation
class RegisterRequestModel {
//{"username":"dummy@mailinator.com","password":"1",
//"clientId":"172017F9EC11222E8107142733:QRK2UM0Q:","uuid":"c4183275a65bc9ce",
//"appVersion":"1","phoneBrand":"ONEPLUS A5000","phoneOS":"8.1.0",
//"fcmId":"clnYxGGL-Fw:APA91bELC9Oomz35tdS3pfmVGaChObAE0y6utiscMqpB0i-d05GMP5f1FjS",
//"osVersion":"27"}
class RegisterRequestModel: Serializer {
var username: String?
var password: String?
var confirmPassword: String?
@ -20,17 +27,22 @@ class RegisterRequestModel {
var phoneOs: String?
var fcmId: String? // device id
var osVersion: String?
func serialize() -> [String : String] {
var dict = ["":""]
dict["username"] = self.username ?? ""
dict["password"] = self.password ?? ""
dict["clientId"] = self.clientId ?? ""
dict["uuid"] = self.uuid ?? ""
dict["appVersion"] = self.appVersion ?? ""
dict["phoneBrand"] = self.phoneBrand ?? ""
dict["phoneOs"] = self.phoneOs ?? ""
dict["fcmId"] = self.fcmId ?? ""
dict["osVersion"] = self.osVersion ?? ""
return dict
}
}
//sign-up
//Username
//Password
//ClientId
//Imei
//AppVersion
//phoneBrand
//phoneOs
//deviceId
//osVersion

25
GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractor.swift

@ -7,6 +7,7 @@
//
import Foundation
import FirebaseInstanceID
class RegisterInteractor {
@ -45,18 +46,18 @@ class RegisterInteractor {
let uuid = UIDevice.current.identifierForVendor?.uuidString
return uuid
}
// MARK: Converting entities
private func getFcmToken() -> String? {
let token = InstanceID.instanceID().token()
return token
}
// MARK: Register interactor input interface
private func getCliendId() -> String {
return "172017F9EC11222E8107142733"
}
// MARK: Converting entities
}
// uuid // service
// ClientId // service
// AppVersion
// phoneBrand // ipod ipad
// phoneOs // iOS
// deviceId
// osVersion // version 11.04
extension RegisterInteractor: RegisterInteractorInput {
func register(model: RegisterRequestModel) {
@ -65,7 +66,11 @@ extension RegisterInteractor: RegisterInteractorInput {
model.phoneBrand = self.getPhoneBrand()
model.phoneOs = self.getPhoneOs()
model.osVersion = self.getOsVersion()
let clientId = "172017F9EC11222E8107142733:QRK2UM0Q"
model.fcmId = self.getFcmToken()
let clientId = self.getCliendId()
let params = model.serialize()
}
}

12
GMERemittance/Module/Register/Application Logic/Service/RegisterServiceType.swift

@ -14,18 +14,6 @@ protocol RegisterServiceType: class {
}
//{
// "username": "dummy@mailinator.com",
// "password": "1",
// "clientId": "172017F9EC11222E8107142733:QRK2UM0Q:",
// "uuid": "c4183275a65bc9ce",
// "appVersion": "1",
// "phoneBrand": "ONEPLUS A5000",
// "phoneOS": "8.1.0",
// "fcmId": "clnYxGGL-Fw:APA91bELC9Oomz35tdS3pfmVGaChObAE0y6ut81C0MhW6cqa6CBPB33gYQb2MIwpbtxMi29Cd85VfICoScHdkDMAbiSM_qBMErzWAE3cg3nN76OTyM8AnjiscMqpB0i-d05GMP5f1FjS",
// "osVersion": "27"
//}
protocol RegisterUserService: ApiServiceType {
func register(params: [String: String], success: @escaping () -> (), failure: @escaping (Error) -> ())

Loading…
Cancel
Save