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

Add NotificationManager and local notification #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions Chatterbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
036749702A4B61FF001CFFBF /* ProfileViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0367496F2A4B61FF001CFFBF /* ProfileViewModel.swift */; };
036749732A4B62A2001CFFBF /* ConversationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036749722A4B62A2001CFFBF /* ConversationCell.swift */; };
036749782A4C0E85001CFFBF /* MessageKindExstensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036749772A4C0E85001CFFBF /* MessageKindExstensions.swift */; };
03D252C12A84FE22004126AF /* AppDelegateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D252C02A84FE22004126AF /* AppDelegateExtension.swift */; };
03D252C32A850568004126AF /* NotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D252C22A850568004126AF /* NotificationManager.swift */; };
03DE3F8E2A4C2D79009A7060 /* ContactsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DE3F8D2A4C2D79009A7060 /* ContactsViewController.swift */; };
03DE3F922A4C3704009A7060 /* ContactCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DE3F912A4C3704009A7060 /* ContactCell.swift */; };
03DE3F982A4C60B1009A7060 /* SearchResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DE3F972A4C60B0009A7060 /* SearchResults.swift */; };
Expand Down Expand Up @@ -66,6 +68,8 @@
0367496F2A4B61FF001CFFBF /* ProfileViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewModel.swift; sourceTree = "<group>"; };
036749722A4B62A2001CFFBF /* ConversationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationCell.swift; sourceTree = "<group>"; };
036749772A4C0E85001CFFBF /* MessageKindExstensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageKindExstensions.swift; sourceTree = "<group>"; };
03D252C02A84FE22004126AF /* AppDelegateExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegateExtension.swift; sourceTree = "<group>"; };
03D252C22A850568004126AF /* NotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManager.swift; sourceTree = "<group>"; };
03DE3F8D2A4C2D79009A7060 /* ContactsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsViewController.swift; sourceTree = "<group>"; };
03DE3F912A4C3704009A7060 /* ContactCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactCell.swift; sourceTree = "<group>"; };
03DE3F972A4C60B0009A7060 /* SearchResults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResults.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -115,6 +119,7 @@
children = (
0367491C2A43553F001CFFBF /* AppDelegate.swift */,
0367491E2A43553F001CFFBF /* SceneDelegate.swift */,
03D252BF2A84FE01004126AF /* Notifications */,
036749632A4A3A30001CFFBF /* Databases */,
036749422A436D35001CFFBF /* Login */,
03DE3F902A4C356A009A7060 /* Contacts */,
Expand Down Expand Up @@ -216,6 +221,15 @@
path = SupportFiles;
sourceTree = "<group>";
};
03D252BF2A84FE01004126AF /* Notifications */ = {
isa = PBXGroup;
children = (
03D252C02A84FE22004126AF /* AppDelegateExtension.swift */,
03D252C22A850568004126AF /* NotificationManager.swift */,
);
path = Notifications;
sourceTree = "<group>";
};
03DE3F8F2A4C3528009A7060 /* Chat */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -393,6 +407,7 @@
036749702A4B61FF001CFFBF /* ProfileViewModel.swift in Sources */,
03DE3FA72A52D389009A7060 /* ConversationModel.swift in Sources */,
03DE3FA92A5599FF009A7060 /* MessageManager.swift in Sources */,
03D252C32A850568004126AF /* NotificationManager.swift in Sources */,
0367493F2A435DEF001CFFBF /* NewConversationViewController.swift in Sources */,
0367494C2A44A335001CFFBF /* TabBarViewController.swift in Sources */,
03DE3F982A4C60B1009A7060 /* SearchResults.swift in Sources */,
Expand All @@ -408,6 +423,7 @@
036749582A478620001CFFBF /* StorageManager.swift in Sources */,
036749662A4B0C0B001CFFBF /* NotificationExstensions.swift in Sources */,
0367491F2A43553F001CFFBF /* SceneDelegate.swift in Sources */,
03D252C12A84FE22004126AF /* AppDelegateExtension.swift in Sources */,
03DE3F8E2A4C2D79009A7060 /* ContactsViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,24 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "347"
endingLineNumber = "347"
landmarkName = "LoginViewController"
landmarkType = "3">
landmarkName = "loginButton(_:didCompleteWith:error:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "A23E6BC9-2FD2-4C9D-ADD8-F7F0468B39CD"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Chatterbox/Notifications/AppDelegateExtension.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "17"
endingLineNumber = "17"
landmarkName = "AppDelegate"
landmarkType = "21">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
Expand Down
14 changes: 12 additions & 2 deletions Chatterbox/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ import FirebaseCore
import FirebaseAuth
import FBSDKCoreKit
import GoogleSignIn
import UserNotifications

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

public var signInConfig: GIDConfiguration?
private let notificationCenter = UNUserNotificationCenter.current()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

FirebaseApp.configure()

notificationCenter.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
guard granted else { return }
self.notificationCenter.getNotificationSettings { settings in
guard settings.authorizationStatus == .authorized else { return }
}
}

notificationCenter.delegate = self
NotificationManager.shared.sendNotification()

// Facebook login
// ApplicationDelegate.shared.application(
// application,
Expand Down Expand Up @@ -126,5 +138,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
})
}
}


22 changes: 22 additions & 0 deletions Chatterbox/Notifications/AppDelegateExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// AppDelegateExtension.swift
// Chatterbox
//
// Created by Александра Кострова on 10.08.2023.
//


import UserNotifications

extension AppDelegate: UNUserNotificationCenterDelegate {
//the app on screen
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.banner, .sound])
print("notification was presented")
}

//click on notification
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("click on notification")
}
}
32 changes: 32 additions & 0 deletions Chatterbox/Notifications/NotificationManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// NotificationManager.swift
// Chatterbox
//
// Created by Александра Кострова on 10.08.2023.
//

import UserNotifications

final class NotificationManager {

static let shared = NotificationManager()

func sendNotification() {
let content = UNMutableNotificationContent()
content.title = "You have a new message"
content.body = "Sender's username here"
content.sound = UNNotificationSound.default

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3, repeats: false)

// create request
let request = UNNotificationRequest(identifier: "notification",
content: content,
trigger: trigger)
// create request to NotificationCenter
UNUserNotificationCenter.current().add(request) { error in
print(error?.localizedDescription as Any)
}
}

}
28 changes: 14 additions & 14 deletions Pods/AppAuth/Source/AppAuth/iOS/OIDExternalUserAgentIOS.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading