diff --git a/Podfile b/Podfile index 7c2b6f10..482be536 100644 --- a/Podfile +++ b/Podfile @@ -21,6 +21,7 @@ target 'TCAT' do # Analytics pod 'Firebase' pod 'FirebaseCrashlytics' + pod 'Firebase/Messaging' # File Management pod 'Zip', '~> 1.1' diff --git a/Podfile.lock b/Podfile.lock index f5a62843..f3cd992e 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -10,6 +10,9 @@ PODS: - FirebaseAnalytics (~> 10.24.0) - Firebase/CoreOnly (10.24.0): - FirebaseCore (= 10.24.0) + - Firebase/Messaging (10.24.0): + - Firebase/CoreOnly + - FirebaseMessaging (~> 10.24.0) - FirebaseAnalytics (10.24.0): - FirebaseAnalytics/AdIdSupport (= 10.24.0) - FirebaseCore (~> 10.0) @@ -50,6 +53,15 @@ PODS: - GoogleUtilities/Environment (~> 7.8) - GoogleUtilities/UserDefaults (~> 7.8) - PromisesObjC (~> 2.1) + - FirebaseMessaging (10.24.0): + - FirebaseCore (~> 10.0) + - FirebaseInstallations (~> 10.0) + - GoogleDataTransport (~> 9.3) + - GoogleUtilities/AppDelegateSwizzler (~> 7.8) + - GoogleUtilities/Environment (~> 7.8) + - GoogleUtilities/Reachability (~> 7.8) + - GoogleUtilities/UserDefaults (~> 7.8) + - nanopb (< 2.30911.0, >= 2.30908.0) - FirebaseRemoteConfigInterop (10.24.0) - FirebaseSessions (10.24.0): - FirebaseCore (~> 10.5) @@ -142,6 +154,7 @@ DEPENDENCIES: - Apollo (~> 1.9.3) - DZNEmptyDataSet (from `https://github.com/cuappdev/DZNEmptyDataSet.git`) - Firebase + - Firebase/Messaging - FirebaseCrashlytics - FutureNova (from `https://github.com/cuappdev/ios-networking.git`) - GoogleMaps @@ -165,6 +178,7 @@ SPEC REPOS: - FirebaseCoreInternal - FirebaseCrashlytics - FirebaseInstallations + - FirebaseMessaging - FirebaseRemoteConfigInterop - FirebaseSessions - GoogleAppMeasurement @@ -213,6 +227,7 @@ SPEC CHECKSUMS: FirebaseCoreInternal: bcb5acffd4ea05e12a783ecf835f2210ce3dc6af FirebaseCrashlytics: af38ea4adfa606f6e63fcc22091b61e7938fcf66 FirebaseInstallations: 8f581fca6478a50705d2bd2abd66d306e0f5736e + FirebaseMessaging: 4d52717dd820707cc4eadec5eb981b4832ec8d5d FirebaseRemoteConfigInterop: 6c349a466490aeace3ce9c091c86be1730711634 FirebaseSessions: 2651b464e241c93fd44112f995d5ab663c970487 FutureNova: 95f9aa352b2c250253b96fdf380754afcc87c7f3 @@ -234,6 +249,6 @@ SPEC CHECKSUMS: Wormholy: ab1c8c2f02f58587a0941deb0088555ffbf039a1 Zip: 8877eede3dda76bcac281225c20e71c25270774c -PODFILE CHECKSUM: a3b80dd04ea30998a17c032f2730e21ee8517238 +PODFILE CHECKSUM: 03571a87e3df2cb79c3c62b5bd19cd6713131c52 COCOAPODS: 1.15.2 diff --git a/TCAT.xcodeproj/project.pbxproj b/TCAT.xcodeproj/project.pbxproj index 7dfabf64..7871ee40 100644 --- a/TCAT.xcodeproj/project.pbxproj +++ b/TCAT.xcodeproj/project.pbxproj @@ -127,6 +127,7 @@ BF74AC1E1F945D8E00AFD4E4 /* GoogleMaps.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF74AC1C1F945D8E00AFD4E4 /* GoogleMaps.framework */; }; D4756EA223986CB500FE7F0D /* ReachabilityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4756EA123986CB500FE7F0D /* ReachabilityManager.swift */; }; DD3D9C211F94297100B164D4 /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3D9C201F94297100B164D4 /* Reachability.swift */; }; + EEB26AE22C9F9B9A002E863F /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEB26AE12C9F9B9A002E863F /* UserNotifications.framework */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -271,6 +272,9 @@ BF74AC1C1F945D8E00AFD4E4 /* GoogleMaps.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GoogleMaps.framework; path = Pods/GoogleMaps/Maps/Frameworks/GoogleMaps.framework; sourceTree = ""; }; D4756EA123986CB500FE7F0D /* ReachabilityManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReachabilityManager.swift; sourceTree = ""; }; DD3D9C201F94297100B164D4 /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = ""; }; + EEB26AE02C9F998C002E863F /* TCATLocal.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TCATLocal.entitlements; sourceTree = ""; }; + EEB26AE12C9F9B9A002E863F /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; }; + EEB26AE32C9FA60E002E863F /* TCATDebug.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TCATDebug.entitlements; sourceTree = ""; }; FD69AF2A2B89212F00970C7E /* ci_post_clone.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = ci_post_clone.sh; sourceTree = ""; }; /* End PBXFileReference section */ @@ -279,6 +283,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + EEB26AE22C9F9B9A002E863F /* UserNotifications.framework in Frameworks */, BF74AC1D1F945D8E00AFD4E4 /* GoogleMapsCore.framework in Frameworks */, BF74AC1E1F945D8E00AFD4E4 /* GoogleMaps.framework in Frameworks */, BF74AC1A1F945D7D00AFD4E4 /* GoogleMapsBase.framework in Frameworks */, @@ -292,6 +297,7 @@ 12F774CEB5023E6938BDCF3A /* Frameworks */ = { isa = PBXGroup; children = ( + EEB26AE12C9F9B9A002E863F /* UserNotifications.framework */, BF74AC1C1F945D8E00AFD4E4 /* GoogleMaps.framework */, BF74AC1B1F945D8E00AFD4E4 /* GoogleMapsCore.framework */, BF74AC191F945D7D00AFD4E4 /* GoogleMapsBase.framework */, @@ -575,6 +581,8 @@ 449A7C771D80D0E80019300C /* TCAT */ = { isa = PBXGroup; children = ( + EEB26AE32C9FA60E002E863F /* TCATDebug.entitlements */, + EEB26AE02C9F998C002E863F /* TCATLocal.entitlements */, 449A7C7F1D80D0E80019300C /* Assets.xcassets */, 2E70434D2BB75E10003AC1D6 /* PrivacyInfo.xcprivacy */, 2E9416662BC615B0003DEB44 /* Base */, @@ -1077,7 +1085,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; BUNDLE_APP_DISPLAY_NAME = "Ithaca Transit Beta"; - CODE_SIGN_ENTITLEMENTS = TCAT/Supporting/TCAT.entitlements; + CODE_SIGN_ENTITLEMENTS = TCAT/TCATDebug.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; @@ -1176,7 +1184,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; BUNDLE_APP_DISPLAY_NAME = "Ithaca Transit Local"; - CODE_SIGN_ENTITLEMENTS = TCAT/Supporting/TCAT.entitlements; + CODE_SIGN_ENTITLEMENTS = TCAT/TCATLocal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; diff --git a/TCAT/Base/AppDelegate.swift b/TCAT/Base/AppDelegate.swift index fc137710..1a05a5e3 100755 --- a/TCAT/Base/AppDelegate.swift +++ b/TCAT/Base/AppDelegate.swift @@ -13,12 +13,13 @@ import Intents import SafariServices import SwiftyJSON import UIKit +import FirebaseMessaging /// This is used for app-specific preferences let userDefaults = UserDefaults.standard @UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate { +class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate, UNUserNotificationCenterDelegate { var window: UIWindow? private let encoder = JSONEncoder() @@ -36,7 +37,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Set Up Google Services FirebaseApp.configure() - + GMSServices.provideAPIKey(TransitEnvironment.googleMaps) // Update shortcut items @@ -90,6 +91,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate { self.window = UIWindow(frame: UIScreen.main.bounds) self.window?.rootViewController = navigationController self.window?.makeKeyAndVisible() + + //Set up notifications + UNUserNotificationCenter.current().delegate = self + + let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] + UNUserNotificationCenter.current().requestAuthorization( + options: authOptions, + completionHandler: { _, _ in } + ) + + application.registerForRemoteNotifications() + + + Messaging.messaging().delegate = self + + + + + + return true } @@ -97,6 +118,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { handleShortcut(item: shortcutItem) } + + func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + Messaging.messaging().apnsToken = deviceToken + Messaging.messaging().token { token, error in + if let error = error { + print("Error fetching FCM registration token: \(error)") + } else if let token = token { + print("FCM registration token: \(token)") + + } + } + + } + func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { + print("application didFailToRegisterForRemoteNotificationsWithError") + } // MARK: - Helper Functions @@ -206,3 +243,31 @@ extension UIWindow { } } + +extension AppDelegate { + +//MessagingDelegate +// func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { +// self.firebaseToken = fcmToken! +// print("Firebase token: \(fcmToken)") +// } + + func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { + print("Firebase registration token: \(String(describing: fcmToken))") + + let dataDict: [String: String] = ["token": fcmToken ?? ""] + NotificationCenter.default.post( + name: Notification.Name("FCMToken"), + object: nil, + userInfo: dataDict + ) + // TODO: If necessary send token to application server. + // Note: This callback is fired at each app startup and whenever a new token is generated. + } + + //UNUserNotificationCenterDelegate + func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { + print("APNs received with: \(userInfo)") + } + +} diff --git a/TCAT/Supporting/Info.plist b/TCAT/Supporting/Info.plist index d54da69f..2e3c25cb 100755 --- a/TCAT/Supporting/Info.plist +++ b/TCAT/Supporting/Info.plist @@ -69,7 +69,9 @@ UIBackgroundModes + fetch location + remote-notification UILaunchStoryboardName LaunchScreen diff --git a/TCAT/Supporting/TCAT.entitlements b/TCAT/Supporting/TCAT.entitlements index 410c063f..531c4668 100644 --- a/TCAT/Supporting/TCAT.entitlements +++ b/TCAT/Supporting/TCAT.entitlements @@ -2,6 +2,8 @@ + aps-environment + development com.apple.security.application-groups group.tcat diff --git a/TCAT/TCATDebug.entitlements b/TCAT/TCATDebug.entitlements new file mode 100644 index 00000000..531c4668 --- /dev/null +++ b/TCAT/TCATDebug.entitlements @@ -0,0 +1,12 @@ + + + + + aps-environment + development + com.apple.security.application-groups + + group.tcat + + + diff --git a/TCAT/TCATLocal.entitlements b/TCAT/TCATLocal.entitlements new file mode 100644 index 00000000..531c4668 --- /dev/null +++ b/TCAT/TCATLocal.entitlements @@ -0,0 +1,12 @@ + + + + + aps-environment + development + com.apple.security.application-groups + + group.tcat + + +