Archived
Added Firebase Cloud Messaging capabilities [UNTESTED]
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Firebase
|
||||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
@@ -15,7 +16,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
|
||||
FirebaseApp.configure()
|
||||
|
||||
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()
|
||||
|
||||
Messaging.messaging().subscribe(toTopic: "substitutions") { error in
|
||||
print("Subscribed to substitutions topic")
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -40,6 +62,43 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
|
||||
// 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 = userInfo[gcmMessageIDKey] {
|
||||
print("Message ID: \(messageID)")
|
||||
}
|
||||
|
||||
// Print full message.
|
||||
print(userInfo)
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
|
||||
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
||||
// 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 = userInfo[gcmMessageIDKey] {
|
||||
print("Message ID: \(messageID)")
|
||||
}
|
||||
|
||||
// Print full message.
|
||||
print(userInfo)
|
||||
|
||||
completionHandler(UIBackgroundFetchResult.newData)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
<?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>CLIENT_ID</key>
|
||||
<string>90133755549-74enm9fefgrj5v5009c11194qi71m09f.apps.googleusercontent.com</string>
|
||||
<key>REVERSED_CLIENT_ID</key>
|
||||
<string>com.googleusercontent.apps.90133755549-74enm9fefgrj5v5009c11194qi71m09f</string>
|
||||
<key>API_KEY</key>
|
||||
<string>AIzaSyA72p4vjr7gbrQ1Y1V7-AMYuwJTF7asgiI</string>
|
||||
<key>GCM_SENDER_ID</key>
|
||||
<string>90133755549</string>
|
||||
<key>PLIST_VERSION</key>
|
||||
<string>1</string>
|
||||
<key>BUNDLE_ID</key>
|
||||
<string>denizd.AvH-Plan</string>
|
||||
<key>PROJECT_ID</key>
|
||||
<string>avh-plan</string>
|
||||
<key>STORAGE_BUCKET</key>
|
||||
<string>avh-plan.appspot.com</string>
|
||||
<key>IS_ADS_ENABLED</key>
|
||||
<false></false>
|
||||
<key>IS_ANALYTICS_ENABLED</key>
|
||||
<false></false>
|
||||
<key>IS_APPINVITE_ENABLED</key>
|
||||
<true></true>
|
||||
<key>IS_GCM_ENABLED</key>
|
||||
<true></true>
|
||||
<key>IS_SIGNIN_ENABLED</key>
|
||||
<true></true>
|
||||
<key>GOOGLE_APP_ID</key>
|
||||
<string>1:90133755549:ios:7f4e659b77a89ab9</string>
|
||||
<key>DATABASE_URL</key>
|
||||
<string>https://avh-plan.firebaseio.com</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Reference in New Issue
Block a user