-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of Push Notifications (#266)
- Loading branch information
1 parent
317fde2
commit 12ac129
Showing
10 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
BuyPolish/Pola/Manager/NotificationManager/NotificationManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
final class NotificationManager: NSObject, NotificationProvider { | ||
func register(in application: UIApplication) { | ||
UNUserNotificationCenter.current().delegate = self | ||
|
||
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] | ||
UNUserNotificationCenter.current().requestAuthorization( | ||
options: authOptions, | ||
completionHandler: { _, _ in } | ||
) | ||
|
||
application.registerForRemoteNotifications() | ||
} | ||
} | ||
|
||
extension NotificationManager: UNUserNotificationCenterDelegate { | ||
func userNotificationCenter(_: UNUserNotificationCenter, | ||
willPresent _: UNNotification, | ||
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) | ||
-> Void) { | ||
completionHandler([[.alert, .sound]]) | ||
} | ||
|
||
func userNotificationCenter(_: UNUserNotificationCenter, | ||
didReceive _: UNNotificationResponse, | ||
withCompletionHandler completionHandler: @escaping () -> Void) { | ||
completionHandler() | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
BuyPolish/Pola/Manager/NotificationManager/NotificationProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import UIKit | ||
protocol NotificationProvider { | ||
func register(in application: UIApplication) | ||
} |
10 changes: 10 additions & 0 deletions
10
BuyPolish/Pola/Manager/NotificationManager/NotificationRegistrant.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Firebase | ||
import Swinject | ||
|
||
final class NotificationRegistrant: DependencyRegistrant { | ||
func registerDependency(container: Container) { | ||
container.register(NotificationProvider.self) { _ in | ||
NotificationManager() | ||
}.inObjectScope(.container) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?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>aps-environment</key> | ||
<string>development</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?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/> | ||
</plist> |