Skip to content

Commit

Permalink
9 jun
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddhesh44 committed Jun 9, 2020
1 parent 11a1095 commit 8bca70b
Show file tree
Hide file tree
Showing 34 changed files with 1,505 additions and 230 deletions.
44 changes: 44 additions & 0 deletions Begin.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

141 changes: 139 additions & 2 deletions Begin/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import GoogleSignIn
import FacebookCore
import FacebookLogin
import IQKeyboardManagerSwift
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate, MessagingDelegate {


// MARK: Google Maps
Expand All @@ -31,7 +32,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

// facebook login

ApplicationDelegate.shared.application(application,didFinishLaunchingWithOptions: launchOptions)
ApplicationDelegate.shared.application(application,didFinishLaunchingWithOptions: launchOptions)

// google sign in
// Initialize sign-in
Expand All @@ -44,6 +45,42 @@ class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

GMSPlacesClient.provideAPIKey("AIzaSyAwLo1vEGHJzCq-hAstZWOcaXQAlPNIBPg")


FirebaseApp.configure()

// [START set_messaging_delegate]
Messaging.messaging().delegate = self
// [END set_messaging_delegate]

InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
print("Error fetching remote instance ID: \(error)")
} else if let result = result {
print("Remote instance ID token: \(result.token)")
// self.instanceIDTokenMessage.text = "Remote InstanceID token: \(result.token)"
}
}


// [START register_for_notifications]
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()

// [END register_for_notifications]

return true
}

Expand Down Expand Up @@ -154,5 +191,105 @@ class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
}
}
}


// setup client
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(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.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}

private func application(application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
Messaging.messaging().apnsToken = deviceToken as Data
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("FailToRegisterForRemoteNotifications",error)
}
// receive messages
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)
}



}


@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {

// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo

// 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)

// Change this to your preferred presentation option
completionHandler([[.alert, .badge, .sound]])
}

func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
// if let messageID = userInfo[gcmMessageIDKey] {
// print("Message ID: \(messageID)")
// }

// Print full message.
print(userInfo)

completionHandler()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"images" : [
{
"idiom" : "universal",
"filename" : "Pin.png",
"scale" : "1x"
},
{
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Group 476.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Group [email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Group [email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Begin/Begin.entitlements
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>
36 changes: 36 additions & 0 deletions Begin/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -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>1062031380552-h5mlttp00696dnb35ihccbkh64m4stjb.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.1062031380552-h5mlttp00696dnb35ihccbkh64m4stjb</string>
<key>API_KEY</key>
<string>AIzaSyCRJv5pMOWuclRC2yt-xffxEb4kOavXkWs</string>
<key>GCM_SENDER_ID</key>
<string>1062031380552</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.infiny.Begin</string>
<key>PROJECT_ID</key>
<string>learnfirebase-48999</string>
<key>STORAGE_BUCKET</key>
<string>learnfirebase-48999.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:1062031380552:ios:64f0247297344b5278487d</string>
<key>DATABASE_URL</key>
<string>https://learnfirebase-48999.firebaseio.com</string>
</dict>
</plist>
Loading

0 comments on commit 8bca70b

Please sign in to comment.