3
3
// Commun
4
4
//
5
5
// Created by Maxim Prigozhenkov on 14/03/2019.
6
- // Copyright © 2019 Maxim Prigozhenkov . All rights reserved.
6
+ // Copyright © 2019 Commun Limited . All rights reserved.
7
7
//
8
8
// https://console.firebase.google.com/project/golos-5b0d5/notification/compose?campaignId=9093831260433778480&dupe=true
9
9
//
@@ -34,7 +34,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
34
34
let notificationCenter = UNUserNotificationCenter . current ( )
35
35
36
36
private var bag = DisposeBag ( )
37
-
38
37
39
38
// MARK: - Class Functions
40
39
func application( _ application: UIApplication , didFinishLaunchingWithOptions launchOptions: [ UIApplication . LaunchOptionsKey : Any ] ? ) -> Bool {
@@ -73,7 +72,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
73
72
. take ( 1 )
74
73
. asSingle ( )
75
74
. timeout ( 5 , scheduler: MainScheduler . instance)
76
- . subscribe ( onSuccess: { ( connected ) in
75
+ . subscribe ( onSuccess: { ( _ ) in
77
76
AppDelegate . reloadSubject. onNext ( false )
78
77
self . window? . makeKeyAndVisible ( )
79
78
application. applicationIconBadgeNumber = 0
@@ -125,15 +124,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
125
124
126
125
// if all set
127
126
RestAPIManager . instance. authorize ( )
128
- . subscribe ( onSuccess: { ( response ) in
127
+ . subscribe ( onSuccess: { ( _ ) in
129
128
// Retrieve favourites
130
129
FavouritesList . shared. retrieve ( )
131
130
132
131
// Turn notify on
133
132
self . pushNotifyOn ( )
134
133
135
134
// show feed
136
- if ( !force && ( self . window? . rootViewController is TabBarVC ) ) { return }
135
+ if !force && ( self . window? . rootViewController is TabBarVC ) { return }
137
136
self . changeRootVC ( controllerContainer. resolve ( TabBarVC . self) !)
138
137
} , onError: { ( error) in
139
138
if let error = error as? ErrorAPI {
@@ -173,9 +172,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
173
172
let navigationBarAppearace = UINavigationBar . appearance ( )
174
173
navigationBarAppearace. tintColor = #colorLiteral( red: 0.4156862745 , green: 0.5019607843 , blue: 0.9607843137 , alpha: 1 )
175
174
navigationBarAppearace. largeTitleTextAttributes = [
176
- NSAttributedString . Key. foregroundColor: UIColor . black,
177
- NSAttributedString . Key. font: UIFont ( name: " SFProDisplay-Bold " ,
178
- size: 30.0 * Config. widthRatio) !
175
+ NSAttributedString . Key. foregroundColor: UIColor . black,
176
+ NSAttributedString . Key. font: UIFont ( name: " SFProDisplay-Bold " ,
177
+ size: 30.0 * Config. widthRatio) !
179
178
]
180
179
}
181
180
}
@@ -215,10 +214,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
215
214
}
216
215
} )
217
216
}
218
-
219
217
}
220
218
221
- func getConfig( completion: @escaping ( ( Error ? ) -> Void ) ) {
219
+ func getConfig( completion: @escaping ( ( Error ? ) -> Void ) ) {
222
220
RestAPIManager . instance. getConfig ( )
223
221
. subscribe ( onSuccess: { _ in
224
222
completion ( nil )
@@ -232,26 +230,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
232
230
SocketManager . shared. disconnect ( )
233
231
}
234
232
235
- func applicationDidEnterBackground( _ application: UIApplication ) {
236
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
237
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
238
- // NetworkService.shared.disconnect()
239
- }
240
-
241
233
func applicationWillEnterForeground( _ application: UIApplication ) {
242
- // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
243
234
SocketManager . shared. connect ( )
244
235
}
245
236
246
- func applicationDidBecomeActive( _ application: UIApplication ) {
247
- // NetworkService.shared.connect()
248
- }
249
-
250
237
func applicationWillTerminate( _ application: UIApplication ) {
251
238
SocketManager . shared. disconnect ( )
252
239
self . saveContext ( )
253
240
}
254
-
255
241
256
242
// MARK: - Custom Functions
257
243
private func configureNotifications( application: UIApplication ) {
@@ -261,8 +247,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
261
247
// Configure notificationCenter
262
248
self . notificationCenter. delegate = self
263
249
264
- self . notificationCenter. requestAuthorization ( options: [ . alert, . sound, . badge] ,
265
- completionHandler: { ( granted, error ) in
250
+ self . notificationCenter. requestAuthorization ( options: [ . alert, . sound, . badge] ,
251
+ completionHandler: { ( granted, _ ) in
266
252
Logger . log ( message: " Permission granted: \( granted) " , event: . debug)
267
253
guard granted else { return }
268
254
self . getNotificationSettings ( )
@@ -273,12 +259,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
273
259
}
274
260
275
261
private func getNotificationSettings( ) {
276
- self . notificationCenter. getNotificationSettings ( completionHandler: { ( settings) in
262
+ self . notificationCenter. getNotificationSettings ( completionHandler: { ( settings) in
277
263
Logger . log ( message: " Notification settings: \( settings) " , event: . debug)
278
264
} )
279
265
}
280
266
281
- private func scheduleLocalNotification( userInfo: [ AnyHashable : Any ] ) {
267
+ private func scheduleLocalNotification( userInfo: [ AnyHashable : Any ] ) {
282
268
let notificationContent = UNMutableNotificationContent ( )
283
269
let categoryIdentifier = userInfo [ " category " ] as? String ?? " Commun "
284
270
@@ -301,10 +287,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
301
287
let snoozeAction = UNNotificationAction ( identifier: " ActionSnooze " , title: " Snooze " . localized ( ) , options: [ ] )
302
288
let deleteAction = UNNotificationAction ( identifier: " ActionDelete " , title: " delete " . localized ( ) . uppercaseFirst, options: [ . destructive] )
303
289
304
- let category = UNNotificationCategory ( identifier: categoryIdentifier,
305
- actions: [ snoozeAction, deleteAction] ,
306
- intentIdentifiers: [ ] ,
307
- options: [ ] )
290
+ let category = UNNotificationCategory ( identifier: categoryIdentifier,
291
+ actions: [ snoozeAction, deleteAction] ,
292
+ intentIdentifiers: [ ] ,
293
+ options: [ ] )
308
294
309
295
self . notificationCenter. setNotificationCategories ( [ category] )
310
296
}
@@ -314,14 +300,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
314
300
RestAPIManager . instance. pushNotifyOn ( )
315
301
. subscribe ( onCompleted: {
316
302
Logger . log ( message: " Successfully turn pushNotificationOn " , event: . severe)
317
- } ) { ( error ) in
303
+ } ) { ( _ ) in
318
304
319
305
}
320
306
. disposed ( by: bag)
321
307
}
322
308
}
323
309
324
-
325
310
// MARK: - Core Data stack
326
311
lazy var persistentContainer : NSPersistentContainer = {
327
312
/*
@@ -331,7 +316,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
331
316
error conditions that could cause the creation of the store to fail.
332
317
*/
333
318
let container = NSPersistentContainer ( name: " Commun " )
334
- container. loadPersistentStores ( completionHandler: { ( storeDescription , error) in
319
+ container. loadPersistentStores ( completionHandler: { ( _ , error) in
335
320
if let error = error as NSError ? {
336
321
// Replace this implementation with code to handle the error appropriately.
337
322
// 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.
@@ -367,11 +352,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
367
352
}
368
353
}
369
354
370
-
371
355
// MARK: - Firebase Cloud Messaging (FCM)
372
356
extension AppDelegate {
373
- func application( _ application: UIApplication ,
374
- didReceiveRemoteNotification userInfo: [ AnyHashable : Any ] ) {
357
+ func application( _ application: UIApplication ,
358
+ didReceiveRemoteNotification userInfo: [ AnyHashable : Any ] ) {
375
359
if let messageID = userInfo [ gcmMessageIDKey] {
376
360
Logger . log ( message: " Message ID: \( messageID) " , event: . severe)
377
361
}
@@ -380,8 +364,8 @@ extension AppDelegate {
380
364
Logger . log ( message: " userInfo: \( userInfo) " , event: . severe)
381
365
}
382
366
383
- func application( _ application: UIApplication ,
384
- didReceiveRemoteNotification userInfo: [ AnyHashable : Any ] ,
367
+ func application( _ application: UIApplication ,
368
+ didReceiveRemoteNotification userInfo: [ AnyHashable : Any ] ,
385
369
fetchCompletionHandler completionHandler: @escaping ( UIBackgroundFetchResult ) -> Void ) {
386
370
if let messageID = userInfo [ gcmMessageIDKey] {
387
371
Logger . log ( message: " Message ID: \( messageID) " , event: . severe)
@@ -393,27 +377,26 @@ extension AppDelegate {
393
377
completionHandler ( UIBackgroundFetchResult . newData)
394
378
}
395
379
396
- func application( _ application: UIApplication ,
397
- didFailToRegisterForRemoteNotificationsWithError error: Error ) {
380
+ func application( _ application: UIApplication ,
381
+ didFailToRegisterForRemoteNotificationsWithError error: Error ) {
398
382
Logger . log ( message: " Unable to register for remote notifications: \( error. localizedDescription) " , event: . error)
399
383
}
400
384
401
- func application( _ application: UIApplication ,
402
- didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) {
385
+ func application( _ application: UIApplication ,
386
+ didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) {
403
387
Logger . log ( message: " APNs token retrieved: \( deviceToken) " , event: . severe)
404
388
405
389
// With swizzling disabled you must set the APNs token here.
406
390
// Messaging.messaging().apnsToken = deviceToken
407
391
}
408
392
}
409
393
410
-
411
394
// MARK: - UNUserNotificationCenterDelegate
412
395
@available ( iOS 10 , * )
413
396
extension AppDelegate : UNUserNotificationCenterDelegate {
414
397
// Receive push-message when App is active/in background
415
- func userNotificationCenter( _ center: UNUserNotificationCenter ,
416
- willPresent notification: UNNotification ,
398
+ func userNotificationCenter( _ center: UNUserNotificationCenter ,
399
+ willPresent notification: UNNotification ,
417
400
withCompletionHandler completionHandler: @escaping ( UNNotificationPresentationOptions ) -> Void ) {
418
401
// Display Local Notification
419
402
let notificationContent = notification. request. content
@@ -427,8 +410,8 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
427
410
}
428
411
429
412
// Tap on push message
430
- func userNotificationCenter( _ center: UNUserNotificationCenter ,
431
- didReceive response: UNNotificationResponse ,
413
+ func userNotificationCenter( _ center: UNUserNotificationCenter ,
414
+ didReceive response: UNNotificationResponse ,
432
415
withCompletionHandler completionHandler: @escaping ( ) -> Void ) {
433
416
let notificationContent = response. notification. request. content
434
417
@@ -443,14 +426,13 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
443
426
}
444
427
}
445
428
446
-
447
429
// MARK: - MessagingDelegate
448
430
extension AppDelegate : MessagingDelegate {
449
- func messaging( _ messaging: Messaging ,
450
- didReceiveRegistrationToken fcmToken: String ) {
431
+ func messaging( _ messaging: Messaging ,
432
+ didReceiveRegistrationToken fcmToken: String ) {
451
433
Logger . log ( message: " FCM registration token: \( fcmToken) " , event: . severe)
452
434
453
- let dataDict : [ String : String ] = [ " token " : fcmToken]
435
+ let dataDict : [ String : String ] = [ " token " : fcmToken]
454
436
NotificationCenter . default. post ( name: Notification . Name ( " FCMToken " ) , object: nil , userInfo: dataDict)
455
437
456
438
UserDefaults . standard. set ( fcmToken, forKey: " fcmToken " )
0 commit comments