diff --git a/nirvana-ios.xcodeproj/project.pbxproj b/nirvana-ios.xcodeproj/project.pbxproj index 3acbabb..0c7e2c9 100644 --- a/nirvana-ios.xcodeproj/project.pbxproj +++ b/nirvana-ios.xcodeproj/project.pbxproj @@ -9,6 +9,9 @@ /* Begin PBXBuildFile section */ 8904DEC8277055E90071E6CA /* OnboardingTrioView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8904DEC7277055E90071E6CA /* OnboardingTrioView.swift */; }; 891060E4277359B900F14509 /* CloudStorageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891060E3277359B900F14509 /* CloudStorageService.swift */; }; + 891060E82774460500F14509 /* FirebaseInAppMessaging-Beta in Frameworks */ = {isa = PBXBuildFile; productRef = 891060E72774460500F14509 /* FirebaseInAppMessaging-Beta */; }; + 891060EA2774460500F14509 /* FirebaseInAppMessagingSwift-Beta in Frameworks */ = {isa = PBXBuildFile; productRef = 891060E92774460500F14509 /* FirebaseInAppMessagingSwift-Beta */; }; + 891060EC2774460500F14509 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 891060EB2774460500F14509 /* FirebaseMessaging */; }; 89110714277166D6005797FA /* UserFriends.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89110713277166D6005797FA /* UserFriends.swift */; }; 891A15E127653A7000B26659 /* nirvana_iosApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891A15E027653A7000B26659 /* nirvana_iosApp.swift */; }; 891A15E327653A7000B26659 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891A15E227653A7000B26659 /* ContentView.swift */; }; @@ -26,7 +29,6 @@ 891A16132765A44300B26659 /* ChatsCarouselViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891A16122765A44300B26659 /* ChatsCarouselViewModel.swift */; }; 892179E42765FEB8001E6C60 /* FooterControlsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892179E32765FEB8001E6C60 /* FooterControlsView.swift */; }; 892179E62765FECD001E6C60 /* FooterControlsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892179E52765FECD001E6C60 /* FooterControlsViewModel.swift */; }; - 89288EC0276755DF00E962C4 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 89288EBF276755DF00E962C4 /* GoogleService-Info.plist */; }; 89288ECB27675B9F00E962C4 /* OnboardingTemplateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89288ECA27675B9F00E962C4 /* OnboardingTemplateView.swift */; }; 894E80BE276ED7A700624B72 /* avatars.swift in Sources */ = {isa = PBXBuildFile; fileRef = 894E80BD276ED7A700624B72 /* avatars.swift */; }; 894E80C1276EFD0500624B72 /* AudioPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 894E80C0276EFD0400624B72 /* AudioPlayerView.swift */; }; @@ -37,6 +39,7 @@ 896CE7052770AE5D00DB474E /* InboxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 896CE7042770AE5D00DB474E /* InboxView.swift */; }; 896CE70727711BAB00DB474E /* FindFriendsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 896CE70627711BAB00DB474E /* FindFriendsView.swift */; }; 896CE70927712CED00DB474E /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 896CE70827712CED00DB474E /* StringExtension.swift */; }; + 89A107E3277446F600B971FD /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 89A107E2277446F600B971FD /* GoogleService-Info.plist */; }; 89AD5573276DD790001658E0 /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89AD5572276DD790001658E0 /* SplashView.swift */; }; 89AD5575276DE724001658E0 /* PhoneCodeVerificationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89AD5574276DE724001658E0 /* PhoneCodeVerificationView.swift */; }; 89AD5578276DEAB3001658E0 /* LogoHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89AD5577276DEAB3001658E0 /* LogoHeaderView.swift */; }; @@ -82,6 +85,7 @@ /* Begin PBXFileReference section */ 8904DEC7277055E90071E6CA /* OnboardingTrioView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingTrioView.swift; sourceTree = ""; }; 891060E3277359B900F14509 /* CloudStorageService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloudStorageService.swift; sourceTree = ""; }; + 891060E527743FEB00F14509 /* nirvana-ios.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "nirvana-ios.entitlements"; sourceTree = ""; }; 89110713277166D6005797FA /* UserFriends.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserFriends.swift; sourceTree = ""; }; 891A15DD27653A7000B26659 /* nirvana-ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "nirvana-ios.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 891A15E027653A7000B26659 /* nirvana_iosApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = nirvana_iosApp.swift; sourceTree = ""; }; @@ -101,7 +105,6 @@ 891A16122765A44300B26659 /* ChatsCarouselViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatsCarouselViewModel.swift; sourceTree = ""; }; 892179E32765FEB8001E6C60 /* FooterControlsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FooterControlsView.swift; sourceTree = ""; }; 892179E52765FECD001E6C60 /* FooterControlsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FooterControlsViewModel.swift; sourceTree = ""; }; - 89288EBF276755DF00E962C4 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; 89288ECA27675B9F00E962C4 /* OnboardingTemplateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingTemplateView.swift; sourceTree = ""; }; 894E80BD276ED7A700624B72 /* avatars.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = avatars.swift; sourceTree = ""; }; 894E80C0276EFD0400624B72 /* AudioPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerView.swift; sourceTree = ""; }; @@ -112,6 +115,7 @@ 896CE7042770AE5D00DB474E /* InboxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxView.swift; sourceTree = ""; }; 896CE70627711BAB00DB474E /* FindFriendsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FindFriendsView.swift; sourceTree = ""; }; 896CE70827712CED00DB474E /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = ""; }; + 89A107E2277446F600B971FD /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../Downloads/GoogleService-Info.plist"; sourceTree = ""; }; 89AD5572276DD790001658E0 /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = ""; }; 89AD5574276DE724001658E0 /* PhoneCodeVerificationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneCodeVerificationView.swift; sourceTree = ""; }; 89AD5577276DEAB3001658E0 /* LogoHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoHeaderView.swift; sourceTree = ""; }; @@ -153,10 +157,13 @@ 89F18AD0276E881800115B1E /* FirebaseAnalyticsSwift-Beta in Frameworks */, 89F18AE6276E881900115B1E /* FirebaseStorage in Frameworks */, 89F18AE2276E881900115B1E /* FirebaseFunctionsCombine-Community in Frameworks */, + 891060E82774460500F14509 /* FirebaseInAppMessaging-Beta in Frameworks */, + 891060EC2774460500F14509 /* FirebaseMessaging in Frameworks */, 89F18AE8276E881900115B1E /* FirebaseStorageCombine-Community in Frameworks */, 89F18ADA276E881900115B1E /* FirebaseFirestore in Frameworks */, 89F18AD6276E881900115B1E /* FirebaseDatabase in Frameworks */, 89F18AD8276E881900115B1E /* FirebaseDatabaseSwift-Beta in Frameworks */, + 891060EA2774460500F14509 /* FirebaseInAppMessagingSwift-Beta in Frameworks */, 89F18ACE276E881800115B1E /* FirebaseAnalytics in Frameworks */, 89F18AE4276E881900115B1E /* FirebaseFunctionsSwift-Beta in Frameworks */, ); @@ -165,11 +172,19 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 891060E62774460500F14509 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; 891A15D427653A7000B26659 = { isa = PBXGroup; children = ( 891A15DF27653A7000B26659 /* nirvana-ios */, 891A15DE27653A7000B26659 /* Products */, + 891060E62774460500F14509 /* Frameworks */, ); sourceTree = ""; }; @@ -184,6 +199,7 @@ 891A15DF27653A7000B26659 /* nirvana-ios */ = { isa = PBXGroup; children = ( + 891060E527743FEB00F14509 /* nirvana-ios.entitlements */, 89AD557D276E01E2001658E0 /* Repositories */, 89F05BA2276ACBFA0002E9C7 /* Services */, 891A160C27657CD600B26659 /* Models */, @@ -194,7 +210,7 @@ 891A15E027653A7000B26659 /* nirvana_iosApp.swift */, 891A15E227653A7000B26659 /* ContentView.swift */, 891A15E427653A7100B26659 /* Assets.xcassets */, - 89288EBF276755DF00E962C4 /* GoogleService-Info.plist */, + 89A107E2277446F600B971FD /* GoogleService-Info.plist */, 891A15E627653A7100B26659 /* Preview Content */, ); path = "nirvana-ios"; @@ -468,6 +484,9 @@ 89F18AE5276E881900115B1E /* FirebaseStorage */, 89F18AE7276E881900115B1E /* FirebaseStorageCombine-Community */, 89F18AE9276E881900115B1E /* FirebaseStorageSwift-Beta */, + 891060E72774460500F14509 /* FirebaseInAppMessaging-Beta */, + 891060E92774460500F14509 /* FirebaseInAppMessagingSwift-Beta */, + 891060EB2774460500F14509 /* FirebaseMessaging */, ); productName = "nirvana-ios"; productReference = 891A15DD27653A7000B26659 /* nirvana-ios.app */; @@ -517,7 +536,7 @@ buildActionMask = 2147483647; files = ( 891A15F12765528700B26659 /* Satisfy-Regular.ttf in Resources */, - 89288EC0276755DF00E962C4 /* GoogleService-Info.plist in Resources */, + 89A107E3277446F600B971FD /* GoogleService-Info.plist in Resources */, 891A15E827653A7100B26659 /* Preview Assets.xcassets in Resources */, 891A15E527653A7100B26659 /* Assets.xcassets in Resources */, ); @@ -706,6 +725,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = "nirvana-ios/nirvana-ios.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -741,6 +761,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = "nirvana-ios/nirvana-ios.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -822,6 +843,21 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 891060E72774460500F14509 /* FirebaseInAppMessaging-Beta */ = { + isa = XCSwiftPackageProductDependency; + package = 89F18ACC276E881800115B1E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = "FirebaseInAppMessaging-Beta"; + }; + 891060E92774460500F14509 /* FirebaseInAppMessagingSwift-Beta */ = { + isa = XCSwiftPackageProductDependency; + package = 89F18ACC276E881800115B1E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = "FirebaseInAppMessagingSwift-Beta"; + }; + 891060EB2774460500F14509 /* FirebaseMessaging */ = { + isa = XCSwiftPackageProductDependency; + package = 89F18ACC276E881800115B1E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseMessaging; + }; 89BCABE1276B3CB0009E9B10 /* NavigationStack */ = { isa = XCSwiftPackageProductDependency; package = 89BCABE0276B3CB0009E9B10 /* XCRemoteSwiftPackageReference "swiftui-navigation-stack" */; diff --git a/nirvana-ios/GoogleService-Info.plist b/nirvana-ios/GoogleService-Info.plist deleted file mode 100644 index 037f934..0000000 --- a/nirvana-ios/GoogleService-Info.plist +++ /dev/null @@ -1,34 +0,0 @@ - - - - - CLIENT_ID - 93806270104-62r53m53imapfocl1sck8bn4ho910ndh.apps.googleusercontent.com - REVERSED_CLIENT_ID - com.googleusercontent.apps.93806270104-62r53m53imapfocl1sck8bn4ho910ndh - API_KEY - AIzaSyCCd0OGpv0fyeNKHDflt42PIiXW09Oz-NA - GCM_SENDER_ID - 93806270104 - PLIST_VERSION - 1 - BUNDLE_ID - com.usenirvana.nirvana-ios - PROJECT_ID - nirvana-ccf04 - STORAGE_BUCKET - nirvana-ccf04.appspot.com - IS_ADS_ENABLED - - IS_ANALYTICS_ENABLED - - IS_APPINVITE_ENABLED - - IS_GCM_ENABLED - - IS_SIGNIN_ENABLED - - GOOGLE_APP_ID - 1:93806270104:ios:108b36b0d2c42381d0e2ed - - \ No newline at end of file diff --git a/nirvana-ios/Info.plist b/nirvana-ios/Info.plist index fa91f90..b70380b 100644 --- a/nirvana-ios/Info.plist +++ b/nirvana-ios/Info.plist @@ -20,6 +20,9 @@ UIBackgroundModes audio + fetch + processing + remote-notification diff --git a/nirvana-ios/nirvana-ios.entitlements b/nirvana-ios/nirvana-ios.entitlements new file mode 100644 index 0000000..903def2 --- /dev/null +++ b/nirvana-ios/nirvana-ios.entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/nirvana-ios/nirvana_iosApp.swift b/nirvana-ios/nirvana_iosApp.swift index 244d2c4..7b48616 100644 --- a/nirvana-ios/nirvana_iosApp.swift +++ b/nirvana-ios/nirvana_iosApp.swift @@ -8,6 +8,7 @@ import SwiftUI import Firebase import GoogleSignIn +import FirebaseMessaging @main struct nirvana_iosApp: App { @@ -27,29 +28,74 @@ struct nirvana_iosApp: App { } class AppDelegate: NSObject, UIApplicationDelegate { + + let gcmMessageIDKey = "gcm.message_id" + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { - print("Colors application is starting up. ApplicationDelegate didFinishLaunchingWithOptions.") + print("application is starting up. ApplicationDelegate didFinishLaunchingWithOptions.") print("initialized Firebase") FirebaseApp.configure() + + // setting up cloud messaging + Messaging.messaging().delegate = self + + // setting up notifications ... requesting authorization from user + 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() + + return true } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { - print("\(#function)") + //MARK: add this when I have APN setup through app // gets the APN token so that firebase can send notifications to app -// Auth.auth().setAPNSToken(deviceToken, type: .sandbox) + Auth.auth().setAPNSToken(deviceToken, type: .sandbox) } func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { print("did receive remote notification") - print("\(#function)") + + // 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 let messageID = notification[gcmMessageIDKey] { + print("Message ID: \(messageID)") + } + + // Print full message. + print(notification) + + completionHandler(UIBackgroundFetchResult.newData) + //MARK: add this when I have APN setup through app -// if Auth.auth().canHandleNotification(notification) { -// completionHandler(.noData) -// return -// } + if Auth.auth().canHandleNotification(notification) { + completionHandler(.noData) + return + } + + } @@ -78,4 +124,67 @@ class AppDelegate: NSObject, UIApplicationDelegate { // URL not auth related, developer should handle it. return true } + + func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { + + } + +} + +// cloud messaging +extension AppDelegate: MessagingDelegate { + func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { + print("Firebase registration token: \(String(describing: fcmToken))") + + let dataDict: [String: String] = ["token": fcmToken ?? ""] + print(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. + } + +} + +// user notifications...in app notifications +@available(iOS 10, *) +extension AppDelegate: UNUserNotificationCenterDelegate { + // Receive displayed notifications for iOS 10 devices. + func userNotificationCenter(_ center: UNUserNotificationCenter, + willPresent notification: UNNotification, + withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) + -> Void) { + let userInfo = notification.request.content.userInfo + + // With swizzling disabled you must let Messaging know about the message, for Analytics + // Messaging.messaging().appDidReceiveMessage(userInfo) + + // ... + + // Print full message. + print(userInfo) + + // Change this to your preferred presentation option + completionHandler([[.alert, .sound]]) + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, + didReceive response: UNNotificationResponse, + withCompletionHandler completionHandler: @escaping () -> Void) { + let userInfo = response.notification.request.content.userInfo + + // ... + + // With swizzling disabled you must let Messaging know about the message, for Analytics + // Messaging.messaging().appDidReceiveMessage(userInfo) + + // Print full message. + print(userInfo) + + completionHandler() + } }