Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 98 additions & 1 deletion GoMoney/AppDelegate/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
import FirebaseCore
import FirebaseMessaging
import GoogleSignIn
import UIKit
import UserNotifications

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
let gcmMessageIDKey = "gcm.message_id"

func application(_: UIApplication, open url: URL, options _: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance.handle(url)
}

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

FirebaseApp.configure()

Messaging.messaging().delegate = self

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 =
.init(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}

application.registerForRemoteNotifications()

return true
}

Expand All @@ -29,4 +52,78 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

func application(_: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any])
{
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
}

func application(_: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any]) async
-> UIBackgroundFetchResult
{
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)

return UIBackgroundFetchResult.newData
}

func application(_: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error)
{
print("Unable to register for remote notifications: \(error.localizedDescription)")
}

func application(_: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
print("APNs token retrieved: \(deviceToken)")
}
}

extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_: UNUserNotificationCenter,
willPresent notification: UNNotification) async
-> UNNotificationPresentationOptions
{
let userInfo = notification.request.content.userInfo

if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}

print(userInfo)
return [[.alert, .sound]]
}

func userNotificationCenter(_: UNUserNotificationCenter,
didReceive response: UNNotificationResponse) async
{
let userInfo = response.notification.request.content.userInfo

if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
}
}

extension AppDelegate: MessagingDelegate {
func 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.
}
}
2 changes: 2 additions & 0 deletions GoMoney/GoMoney.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.kappa.expense</string>
Expand Down
5 changes: 5 additions & 0 deletions GoMoney/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
</array>
</dict>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
<key>UIFileSharingEnabled</key>
<true/>
</dict>
Expand Down
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pod 'FirebaseCore'
pod 'FirebaseAuth'
pod 'FirebaseFirestore'
pod 'FirebaseFirestoreSwift'
pod 'FirebaseMessaging'

pod 'Charts', :git => 'https://github.com/danielgindi/Charts.git', :branch => 'master'
pod 'RealmSwift', '~> 10.32'
Expand Down
29 changes: 28 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,26 @@ PODS:
- FirebaseCoreExtension (~> 10.0)
- FirebaseFirestore (~> 10.0)
- FirebaseSharedSwift (~> 10.0)
- FirebaseInstallations (10.0.0):
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
- PromisesObjC (~> 2.1)
- FirebaseMessaging (10.2.0):
- FirebaseCore (~> 10.0)
- FirebaseInstallations (~> 10.0)
- GoogleDataTransport (~> 9.2)
- GoogleUtilities/AppDelegateSwizzler (~> 7.8)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/Reachability (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
- nanopb (< 2.30910.0, >= 2.30908.0)
- FirebaseSharedSwift (10.1.0)
- Floaty (4.2.0)
- GoogleDataTransport (9.2.0):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleSignIn (6.2.4):
- AppAuth (~> 1.5)
- GTMAppAuth (~> 1.3)
Expand All @@ -666,6 +684,8 @@ PODS:
- "GoogleUtilities/NSData+zlib (7.8.0)"
- GoogleUtilities/Reachability (7.8.0):
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (7.8.0):
- GoogleUtilities/Logger
- GradientLoadingBar (3.0.0)
- "gRPC-C++ (1.44.0)":
- "gRPC-C++/Implementation (= 1.44.0)"
Expand Down Expand Up @@ -757,6 +777,7 @@ DEPENDENCIES:
- FirebaseCore
- FirebaseFirestore
- FirebaseFirestoreSwift
- FirebaseMessaging
- Floaty
- GoogleSignIn
- GradientLoadingBar (~> 3.0)
Expand All @@ -780,8 +801,11 @@ SPEC REPOS:
- FirebaseCoreInternal
- FirebaseFirestore
- FirebaseFirestoreSwift
- FirebaseInstallations
- FirebaseMessaging
- FirebaseSharedSwift
- Floaty
- GoogleDataTransport
- GoogleSignIn
- GoogleUtilities
- GradientLoadingBar
Expand Down Expand Up @@ -826,8 +850,11 @@ SPEC CHECKSUMS:
FirebaseCoreInternal: 5eb3960335da5ea30115d57d39db6988c4ad06f3
FirebaseFirestore: 5007583f3db2129de8e87f18ee63f4c86f07e7a3
FirebaseFirestoreSwift: ba0e8ae1dca6cd395c646671a7fe2dcc077db225
FirebaseInstallations: 7f1c9ae6bd9df6abe9c74124b38fa8740aba5df4
FirebaseMessaging: cc9f40f5b7494680f3844d08e517e92aa4e8d9f7
FirebaseSharedSwift: 6966c4de41fba13a4270de1e421e6eee2cf90113
Floaty: e2bd5a0f6f7f70899e26ff2da31081c8bee8d1b0
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
GoogleSignIn: 5651ce3a61e56ca864160e79b484cd9ed3f49b7a
GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7
GradientLoadingBar: 3c4246535efdedaf9b471c05caabfdb4b87b40a2
Expand All @@ -849,6 +876,6 @@ SPEC CHECKSUMS:
SwiftAlgorithms: 38dda4731d19027fdeee1125f973111bf3386b53
TTGSnackbar: fea91c62637b5662f808a4c3b55f7631cb7e1ef7

PODFILE CHECKSUM: 71ebaf0f62dbee208320c056eb7a0a0f27da3d2e
PODFILE CHECKSUM: 22ee40650525751f14ffe79cbbdb8ee424a7ed85

COCOAPODS: 1.11.3