Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Firebase notifications #577

Merged
merged 2 commits into from
Feb 18, 2024
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
17 changes: 17 additions & 0 deletions HIAPI/Models/Notification.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Notification.swift
// HIAPI
//
// Created by HackIllinois on 2/18/24.
// Copyright © 2024 HackIllinois. All rights reserved.
//

import Foundation
import APIManager

public struct NotificationContainer: Decodable, APIReturnable {
public let success: Bool?
public let status: String?
public let error: String?
}

22 changes: 22 additions & 0 deletions HIAPI/Services/NotificationService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// NotificationService.swift
// HIAPI
//
// Created by HackIllinois on 2/18/24.
// Copyright © 2024 HackIllinois. All rights reserved.
//

import Foundation
import APIManager

public final class NotificationService: BaseService {
public override static var baseURL: String {
return super.baseURL
}

public static func sendDeviceToken(deviceToken: String) -> APIRequest<NotificationContainer> {
var body = HTTPBody()
body["deviceToken"] = deviceToken
return APIRequest<NotificationContainer>(service: self, endpoint: "notification/", body: body, method: .POST)
}
}
37 changes: 33 additions & 4 deletions HackIllinois.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
D14D3AE3295FBDA200EB7995 /* HIBannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14D3AE2295FBDA100EB7995 /* HIBannerViewController.swift */; };
D158EC312B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = D158EC302B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift */; };
D158EC332B5A2DFE0003D799 /* HIScanPointsShopViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D158EC322B5A2DFE0003D799 /* HIScanPointsShopViewController.swift */; };
D187BF582B781A1100AD7356 /* HIShiftCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D187BF572B781A1100AD7356 /* HIShiftCell.swift */; };
D187BF5A2B78317600AD7356 /* Mentor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D187BF592B78317600AD7356 /* Mentor.swift */; };
D187BF5C2B78318000AD7356 /* MentorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D187BF5B2B78318000AD7356 /* MentorService.swift */; };
D19D4C932B794F9100376E1B /* HIScanMentorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19D4C922B794F9100376E1B /* HIScanMentorViewController.swift */; };
Expand All @@ -148,6 +147,12 @@
D1BE81172AC8FC680042C078 /* HIAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95E3142A21FAD5B30092C22E /* HIAPI.framework */; };
D1BE81182AC8FC690042C078 /* HIAPI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 95E3142A21FAD5B30092C22E /* HIAPI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
D1C5B6582B732E44000E766D /* refresh.json in Resources */ = {isa = PBXBuildFile; fileRef = D1C5B6572B732E44000E766D /* refresh.json */; };
D1D335172B81DEBA00BBB596 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = D1D335162B81DEBA00BBB596 /* FirebaseMessaging */; };
D1D335192B81DEF600BBB596 /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1D335182B81DEF600BBB596 /* Notification.swift */; };
D1D3351B2B81DF0300BBB596 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1D3351A2B81DF0300BBB596 /* NotificationService.swift */; };
D1D3351D2B81E11500BBB596 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */; };
D1D3351E2B81E11500BBB596 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */; };
D1D3351F2B81E11500BBB596 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */; };
D1F1463A2B605C57004E7FC9 /* Hack_Mushroom_Loading.json in Resources */ = {isa = PBXBuildFile; fileRef = D1F146392B605C57004E7FC9 /* Hack_Mushroom_Loading.json */; };
D3A309BC2211175200CBA351 /* PassKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3A309BB2211175200CBA351 /* PassKit.framework */; };
D7451BD22B54BCFB00D501D0 /* URLImage in Frameworks */ = {isa = PBXBuildFile; productRef = D7451BD12B54BCFB00D501D0 /* URLImage */; };
Expand Down Expand Up @@ -357,13 +362,15 @@
D14D3AE2295FBDA100EB7995 /* HIBannerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIBannerViewController.swift; sourceTree = "<group>"; };
D158EC302B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIQRAttendeeScannerSelection.swift; sourceTree = "<group>"; };
D158EC322B5A2DFE0003D799 /* HIScanPointsShopViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIScanPointsShopViewController.swift; sourceTree = "<group>"; };
D187BF572B781A1100AD7356 /* HIShiftCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIShiftCell.swift; sourceTree = "<group>"; };
D187BF592B78317600AD7356 /* Mentor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mentor.swift; sourceTree = "<group>"; };
D187BF5B2B78318000AD7356 /* MentorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentorService.swift; sourceTree = "<group>"; };
D19D4C922B794F9100376E1B /* HIScanMentorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIScanMentorViewController.swift; sourceTree = "<group>"; };
D1BBA5672B70AB940017BD13 /* Staff.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Staff.swift; sourceTree = "<group>"; };
D1BBA5692B70ACCC0017BD13 /* StaffService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaffService.swift; sourceTree = "<group>"; };
D1C5B6572B732E44000E766D /* refresh.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = refresh.json; sourceTree = "<group>"; };
D1D335182B81DEF600BBB596 /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
D1D3351A2B81DF0300BBB596 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
D1F146392B605C57004E7FC9 /* Hack_Mushroom_Loading.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Hack_Mushroom_Loading.json; sourceTree = "<group>"; };
D3A309BA221116A600CBA351 /* HackIllinois.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HackIllinois.entitlements; sourceTree = "<group>"; };
D3A309BB2211175200CBA351 /* PassKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PassKit.framework; path = System/Library/Frameworks/PassKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -407,6 +414,7 @@
DF3706562925DE4C000B4278 /* Metal.framework in Frameworks */,
DF3706542925DE47000B4278 /* libz.tbd in Frameworks */,
DF3706522925DE42000B4278 /* libc++.tbd in Frameworks */,
D1D335172B81DEBA00BBB596 /* FirebaseMessaging in Frameworks */,
DF3706502925DE38000B4278 /* ImageIO.framework in Frameworks */,
DF37064E2925DE34000B4278 /* GLKit.framework in Frameworks */,
DF37064C2925DE2F000B4278 /* CoreText.framework in Frameworks */,
Expand Down Expand Up @@ -511,6 +519,7 @@
957DB2E91FC2453100F8C45E /* FlowControllers */,
951827981EA35DB800049F79 /* AppDelegate.swift */,
951827991EA35DB800049F79 /* Assets.xcassets */,
D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */,
9518279E1EA35DB800049F79 /* Controllers */,
9521A6A6201912B4009059C6 /* DataSources */,
958A33E421E143BF00F34C9E /* Extensions */,
Expand Down Expand Up @@ -682,7 +691,6 @@
95A7D282203D4F54005EAEAF /* HIAnnouncementCell.swift */,
95A7D29F203D60E9005EAEAF /* HIBubbleCell.swift */,
95A7D281203D4F54005EAEAF /* HIEventCell.swift */,
D187BF572B781A1100AD7356 /* HIShiftCell.swift */,
3CF8DB1223B419980035ECAE /* HIProjectCell.swift */,
);
path = HIBubbleCell;
Expand Down Expand Up @@ -728,6 +736,7 @@
95E3146221FAF1740092C22E /* AuthService.swift */,
2FA73B4D2B58CAA0002658C0 /* ShopService.swift */,
95E3146121FAF1740092C22E /* BaseService.swift */,
D1D3351A2B81DF0300BBB596 /* NotificationService.swift */,
95B12042220BEA9D00E024BB /* CheckInService.swift */,
95E3145F21FAF1740092C22E /* EventService.swift */,
D187BF5B2B78318000AD7356 /* MentorService.swift */,
Expand All @@ -751,6 +760,7 @@
95E3146821FAF1740092C22E /* Announcement.swift */,
3521FFA82207C03E00634A63 /* Attendee.swift */,
95E3146521FAF1740092C22E /* Event.swift */,
D1D335182B81DEF600BBB596 /* Notification.swift */,
D1BBA5672B70AB940017BD13 /* Staff.swift */,
2FA73B4F2B58CAC3002658C0 /* Item.swift */,
AC3B620D25E85CAD002386A2 /* Profile.swift */,
Expand Down Expand Up @@ -892,6 +902,7 @@
951E67F523C1C83B00477703 /* Keychain */,
951E67F823C1C88200477703 /* Lottie */,
D7451BD12B54BCFB00D501D0 /* URLImage */,
D1D335162B81DEBA00BBB596 /* FirebaseMessaging */,
);
productName = HackIllinois;
productReference = 9518277F1EA35AF100049F79 /* HackIllinois.app */;
Expand Down Expand Up @@ -982,6 +993,7 @@
951E67F423C1C83B00477703 /* XCRemoteSwiftPackageReference "keychain" */,
951E67F723C1C88200477703 /* XCRemoteSwiftPackageReference "lottie-ios" */,
D7451BD02B54BCFB00D501D0 /* XCRemoteSwiftPackageReference "url-image" */,
D1D335152B81DEBA00BBB596 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
);
productRefGroup = 951827801EA35AF100049F79 /* Products */;
projectDirPath = "";
Expand All @@ -1007,6 +1019,7 @@
951827B41EA35E8B00049F79 /* LaunchScreen.storyboard in Resources */,
1C7561A5278E96750004D739 /* LightVespaText.json in Resources */,
D134D30F296B3F56006EA589 /* Montserrat-VariableFont_wght.ttf in Resources */,
D1D3351D2B81E11500BBB596 /* GoogleService-Info.plist in Resources */,
DF37063E2925DDE7000B4278 /* GoogleMaps.bundle in Resources */,
D1C5B6582B732E44000E766D /* refresh.json in Resources */,
);
Expand All @@ -1016,6 +1029,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D1D3351F2B81E11500BBB596 /* GoogleService-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -1024,6 +1038,7 @@
buildActionMask = 2147483647;
files = (
AC607EF0261CD6E300B88798 /* Stickers.xcassets in Resources */,
D1D3351E2B81E11500BBB596 /* GoogleService-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1082,7 +1097,6 @@
E1E4A5DA291C9BF800780BA1 /* HIOnboardingView.swift in Sources */,
95A7D290203D4F54005EAEAF /* HIAnnouncementCell.swift in Sources */,
9515E43722093E1300BCAF92 /* HIEventScannerViewController.swift in Sources */,
D187BF582B781A1100AD7356 /* HIShiftCell.swift in Sources */,
95A7D28F203D4F54005EAEAF /* HIEventCell.swift in Sources */,
ACAA717626017EC4000F42B0 /* HICollectionViewFlowLayout.swift in Sources */,
DF5B27C5299197E80034A8B9 /* Array.swift in Sources */,
Expand Down Expand Up @@ -1174,6 +1188,7 @@
ACB53AEA261B8789007B1643 /* InterestService.swift in Sources */,
3C8F62D4238F9639001A5DAF /* Time.swift in Sources */,
95E3147621FAF1740092C22E /* Announcement.swift in Sources */,
D1D3351B2B81DF0300BBB596 /* NotificationService.swift in Sources */,
95E3146C21FAF1740092C22E /* UserService.swift in Sources */,
95B12043220BEA9D00E024BB /* CheckInService.swift in Sources */,
95E3147121FAF1740092C22E /* AuthService.swift in Sources */,
Expand All @@ -1191,6 +1206,7 @@
3C8F62D6238F9825001A5DAF /* TimeService.swift in Sources */,
D187BF5A2B78317600AD7356 /* Mentor.swift in Sources */,
95E3145921FAD71E0092C22E /* Error.swift in Sources */,
D1D335192B81DEF600BBB596 /* Notification.swift in Sources */,
3C26401D23ADE8A5004E1DBE /* Project.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1595,6 +1611,14 @@
version = 4.0.1;
};
};
D1D335152B81DEBA00BBB596 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/firebase/firebase-ios-sdk";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 9.0.0;
};
};
D7451BD02B54BCFB00D501D0 /* XCRemoteSwiftPackageReference "url-image" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/dmytro-anokhin/url-image";
Expand All @@ -1621,6 +1645,11 @@
package = 951E67F723C1C88200477703 /* XCRemoteSwiftPackageReference "lottie-ios" */;
productName = Lottie;
};
D1D335162B81DEBA00BBB596 /* FirebaseMessaging */ = {
isa = XCSwiftPackageProductDependency;
package = D1D335152B81DEBA00BBB596 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseMessaging;
};
D7451BD12B54BCFB00D501D0 /* URLImage */ = {
isa = XCSwiftPackageProductDependency;
package = D7451BD02B54BCFB00D501D0 /* XCRemoteSwiftPackageReference "url-image" */;
Expand Down
28 changes: 25 additions & 3 deletions HackIllinois/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ import CoreLocation
import UserNotifications
import HIAPI
import GoogleMaps
import Firebase
import FirebaseMessaging

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate, UNUserNotificationCenterDelegate {
private var obfuscatedApiKey: [UInt8] = [92, 213, 228, 193, 244, 27, 239, 139, 188, 14, 85, 191, 47, 237, 55, 13, 85, 89, 111, 212, 35, 80, 45, 104, 189, 229,
33, 32, 70, 63, 90, 163, 173, 232, 167, 90, 203, 22, 169, 29, 156, 158, 160, 167, 98,
174, 239, 247, 118, 96, 207, 104, 180, 14, 90, 58, 61, 89, 186, 89, 7, 114, 25, 255, 141,
115, 113, 117, 78, 10, 150, 197, 161, 158, 98, 129, 87, 228]
var fcmToken: String?
// Handle remote notification registration.
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
guard let user = HIApplicationStateController.shared.user else { return }
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()

Messaging.messaging().apnsToken = deviceToken
Messaging.messaging().delegate = self

// Send the token to notifications server
AnnouncementService.sendToken(deviceToken: token)
NotificationService.sendDeviceToken(deviceToken: fcmToken!)
.onCompletion { result in
do {
_ = try result.get()
Expand All @@ -54,6 +59,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
setupNavigationBarAppearance()
setupTableViewAppearance()
_ = HIThemeEngine.shared
Expand All @@ -63,8 +69,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
HIApplicationStateController.shared.initalize()
// Check the app version and prompt the user to update if needed
checkAppVersion()
application.registerForRemoteNotifications()
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
return true
}

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
// Called when the app has successfully registered with FCM and received a registration token
self.fcmToken = fcmToken

}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// Log the notification details
print(notification.request.content.userInfo)

completionHandler([.alert, .sound, .badge])
}

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.
Expand Down
32 changes: 32 additions & 0 deletions HackIllinois/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-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>API_KEY</key>
<string>placeholder</string>
<key>GCM_SENDER_ID</key>
<string>848675954156</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>org.hackillinois.ios</string>
<key>PROJECT_ID</key>
<string>hackillinois-3787e</string>
<key>STORAGE_BUCKET</key>
<string>hackillinois-3787e.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false/>
<key>IS_ANALYTICS_ENABLED</key>
<false/>
<key>IS_APPINVITE_ENABLED</key>
<true/>
<key>IS_GCM_ENABLED</key>
<true/>
<key>IS_SIGNIN_ENABLED</key>
<true/>
<key>GOOGLE_APP_ID</key>
<string>1:848675954156:ios:d43e052424b30ef97f34c9</string>
<key>DATABASE_URL</key>
<string>https://hackillinois-3787e-default-rtdb.firebaseio.com</string>
</dict>
</plist>
Loading
Loading