fork download
  1. //
  2. // AppDelegate.swift
  3. // DogApp
  4. //
  5. // Created by Admin on 7/3/18.
  6. // Copyright © 2018 Admin. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import Firebase
  11. import FirebaseInstanceID
  12. import FirebaseMessaging
  13. import UserNotifications
  14. import GoogleMaps
  15. import GooglePlaces
  16. import CoreData
  17.  
  18. //import MessagingDelegate
  19. @available(iOS 10.0, *)
  20. @UIApplicationMain
  21. class AppDelegate: UIResponder, UIApplicationDelegate,MessagingDelegate {
  22. static var mangedObjectContext: NSManagedObjectContext?
  23. var window: UIWindow?
  24. let gcmMessageIDKey = "gcm.message_id"
  25. let key = "AIzaSyDzuGKTfmkbR_VBffpJNsgd11Gz7pFOX2c"
  26.  
  27.  
  28. //
  29. // func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  30. //
  31. //
  32. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  33. ///
  34. FirebaseApp.configure()
  35. GMSServices.provideAPIKey("AIzaSyD2kiwgq9e1qFi-z2-iEzdcbvloSNOweBo")
  36. GMSPlacesClient.provideAPIKey("AIzaSyD2kiwgq9e1qFi-z2-iEzdcbvloSNOweBo")
  37. // [START set_messaging_delegate]
  38. Messaging.messaging().delegate = self
  39. // [END set_messaging_delegate]
  40. // Register for remote notifications. This shows a permission dialog on first run, to
  41. // show the dialog at a more appropriate time move this registration accordingly.
  42. // [START register_for_notifications]
  43. if #available(iOS 10.0, *) {
  44. // For iOS 10 display notification (sent via APNS)
  45. UNUserNotificationCenter.current().delegate = self
  46.  
  47. let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
  48. UNUserNotificationCenter.current().requestAuthorization(
  49.  
  50. options: authOptions,
  51. completionHandler: {_, _ in })
  52. } else {
  53. let settings: UIUserNotificationSettings =
  54. UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
  55. application.registerUserNotificationSettings(settings)
  56. }
  57.  
  58. application.registerForRemoteNotifications()
  59.  
  60.  
  61. //
  62.  
  63. AppDelegate.mangedObjectContext = persistentContainer.viewContext
  64. return true
  65. }
  66.  
  67.  
  68. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
  69.  
  70. if let messageID = userInfo[gcmMessageIDKey] {
  71. print("Message ID: \(messageID)")
  72. }
  73.  
  74. print(userInfo)
  75. }
  76.  
  77. func applicationDidFinishLaunching(_ application: UIApplication) {
  78. FirebaseApp.configure()
  79. GMSServices.provideAPIKey("AIzaSyD2kiwgq9e1qFi-z2-iEzdcbvloSNOweBo")
  80. // [START set_messaging_delegate]
  81. Messaging.messaging().delegate = self
  82. // [END set_messaging_delegate]
  83. // Register for remote notifications. This shows a permission dialog on first run, to
  84. // show the dialog at a more appropriate time move this registration accordingly.
  85. // [START register_for_notifications]
  86. if #available(iOS 10.0, *) {
  87. // For iOS 10 display notification (sent via APNS)
  88. UNUserNotificationCenter.current().delegate = self
  89.  
  90. let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
  91. UNUserNotificationCenter.current().requestAuthorization(
  92.  
  93. options: authOptions,
  94. completionHandler: {_, _ in })
  95. } else {
  96. let settings: UIUserNotificationSettings =
  97. UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
  98. application.registerUserNotificationSettings(settings)
  99. }
  100.  
  101. application.registerForRemoteNotifications()
  102.  
  103.  
  104.  
  105. }
  106. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
  107. fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  108.  
  109. if let messageID = userInfo[gcmMessageIDKey] {
  110. print("Message ID: \(messageID)")
  111. }
  112.  
  113. print(userInfo)
  114.  
  115. completionHandler(UIBackgroundFetchResult.newData)
  116. }
  117. func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  118. print("Unable to register for remote notifications: \(error.localizedDescription)")
  119. }
  120.  
  121. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  122. print("APNs token retrieved: \(deviceToken)")
  123.  
  124. }
  125. func application(application: UIApplication,
  126. didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
  127. Messaging.messaging().apnsToken = deviceToken as Data
  128. }
  129.  
  130. func applicationWillResignActive(_ application: UIApplication) {
  131. }
  132.  
  133. func applicationDidEnterBackground(_ application: UIApplication) {
  134. }
  135.  
  136. func applicationWillEnterForeground(_ application: UIApplication) {
  137. }
  138.  
  139. func applicationDidBecomeActive(_ application: UIApplication) {
  140. }
  141.  
  142. func applicationWillTerminate(_ application: UIApplication) {
  143. }
  144. lazy var persistentContainer: NSPersistentContainer = {
  145. /*
  146.   The persistent container for the application. This implementation
  147.   creates and returns a container, having loaded the store for the
  148.   application to it. This property is optional since there are legitimate
  149.   error conditions that could cause the creation of the store to fail.
  150.   */
  151. let container = NSPersistentContainer(name: "Model")
  152. container.loadPersistentStores(completionHandler: { (storeDescription, error) in
  153. if let error = error as NSError? {
  154. // Replace this implementation with code to handle the error appropriately.
  155. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  156.  
  157. /*
  158.   Typical reasons for an error here include:
  159.   * The parent directory does not exist, cannot be created, or disallows writing.
  160.   * The persistent store is not accessible, due to permissions or data protection when the device is locked.
  161.   * The device is out of space.
  162.   * The store could not be migrated to the current model version.
  163.   Check the error message to determine what the actual problem was.
  164.   */
  165. fatalError("Unresolved error \(error), \(error.userInfo)")
  166. }
  167. })
  168. return container
  169. }()
  170.  
  171. // MARK: - Core Data Saving support
  172.  
  173. func saveContext () {
  174. let context = persistentContainer.viewContext
  175. if context.hasChanges {
  176. do {
  177. try context.save()
  178. } catch {
  179. // Replace this implementation with code to handle the error appropriately.
  180. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  181. let nserror = error as NSError
  182. fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
  183. }
  184. }
  185. }
  186.  
  187. }
  188.  
  189. @available(iOS 10, *)
  190. extension AppDelegate : UNUserNotificationCenterDelegate {
  191.  
  192. // Receive displayed notifications for iOS 10 devices.
  193. func userNotificationCenter(_ center: UNUserNotificationCenter,
  194. willPresent notification: UNNotification,
  195. withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  196. let userInfo = notification.request.content.userInfo
  197.  
  198. // With swizzling disabled you must let Messaging know about the message, for Analytics
  199. // Messaging.messaging().appDidReceiveMessage(userInfo)
  200. // Print message ID.
  201. if let messageID = userInfo[gcmMessageIDKey] {
  202. print("Message ID: \(messageID)")
  203. }
  204.  
  205. // Print full message.
  206. print(userInfo)
  207.  
  208. // Change this to your preferred presentation option
  209. completionHandler([.alert,.sound])
  210. }
  211.  
  212. func userNotificationCenter(_ center: UNUserNotificationCenter,
  213. didReceive response: UNNotificationResponse,
  214. withCompletionHandler completionHandler: @escaping () -> Void) {
  215. let userInfo = response.notification.request.content.userInfo
  216. // Print message ID.
  217. if let messageID = userInfo[gcmMessageIDKey] {
  218. print("Message ID: \(messageID)")
  219. }
  220.  
  221. // Print full message.
  222. print(userInfo)
  223. completionHandler()
  224. }
  225. }
  226. @available(iOS 10.0, *)
  227. extension AppDelegate {
  228. // [START refresh_token]
  229.  
  230.  
  231. func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
  232. print("Firebase registration token: \(fcmToken)")
  233. InstanceID.instanceID().instanceID { (result, error) in
  234. if let error = error {
  235. print("Error fetching remote instange ID: \(error)")
  236. } else if let result = result {
  237. print("Remote instance ID token: \(result.token)")
  238. tokenfb = result.token
  239. print("tao dang tesst: \(tokenfb)")
  240.  
  241. }
  242. saveCache(key: "tokenfb", value: tokenfb)
  243. // TODO: If necessary send token to application server.
  244. // Note: This callback is fired at each app startup and whenever a new token is generated.
  245. }
  246. }
  247. // [END refresh_token]
  248. // [START ios_10_data_message]
  249. // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
  250. // To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true.
  251. func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
  252. print("Received data message: \(remoteMessage.appData)")
  253. }
  254. // [END ios_10_data_message]
  255. }
  256.  
  257.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.swift:9:8: error: no such module 'UIKit'
import UIKit
       ^
<unknown>:0: error: error opening input file 'prog.o' (No such file or directory
)
clang: error: no such file or directory: 'prog.o'
clang: error: no such file or directory: '@prog.autolink'
stdout
Standard output is empty