Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 2 | Rev 15 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 2 Rev 12
Línea 71... Línea 71...
71
                  UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
71
                  UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
72
                  application.registerUserNotificationSettings(settings)
72
                  application.registerUserNotificationSettings(settings)
73
                }
73
                }
Línea 74... Línea 74...
74
 
74
 
75
                application.registerForRemoteNotifications()
-
 
76
                return true
75
                application.registerForRemoteNotifications()
77
 
76
        
78
         
77
        
-
 
78
        
-
 
79
        registerBGTasksScheduler()
-
 
80
        scheduleProcess()
79
 
81
        scheduleRefresh()
-
 
82
        
80
 
83
        return true
Línea 81... Línea 84...
81
    }
84
    }
82
    
85
    
Línea 90... Línea 93...
90
 
93
 
91
        processNotification(userInfo: userInfo, isForeground: false)
94
        processNotification(userInfo: userInfo, isForeground: false)
92
        completionHandler(UIBackgroundFetchResult.newData)
95
        completionHandler(UIBackgroundFetchResult.newData)
Línea -... Línea 96...
-
 
96
    }
-
 
97
    
-
 
98
    func registerBGTasksScheduler() {
-
 
99
        BGTaskScheduler.shared.register(forTaskWithIdentifier: Constants.BACKGROUND_TASK_REFRESH, using: nil) { task in
-
 
100
                 self.handleRefreshTask(task: task as! BGAppRefreshTask)
-
 
101
        }
-
 
102
        
-
 
103
        BGTaskScheduler.shared.register(forTaskWithIdentifier: Constants.BACKGROUND_TASK_PROCESS, using: nil) { task in
-
 
104
                 self.handleProcessTask(task: task as! BGProcessingTask)
-
 
105
        }
-
 
106
 
-
 
107
    }
-
 
108
        
-
 
109
    func scheduleRefresh() {
-
 
110
        let request = BGAppRefreshTaskRequest(identifier: Constants.BACKGROUND_TASK_REFRESH)
-
 
111
        request.earliestBeginDate = Date(timeIntervalSinceNow: 10 * 60)
-
 
112
        
-
 
113
 
-
 
114
            
-
 
115
        do {
-
 
116
             try BGTaskScheduler.shared.submit(request)
-
 
117
        } catch {
-
 
118
            print("Could not schedule app refresh: \(error)")
-
 
119
        }
-
 
120
    }
-
 
121
        
-
 
122
    func scheduleProcess() {
-
 
123
        let request = BGProcessingTaskRequest(identifier: Constants.BACKGROUND_TASK_PROCESS)
-
 
124
        request.earliestBeginDate = Date(timeIntervalSinceNow: 10 * 60)
-
 
125
        request.requiresNetworkConnectivity = true
-
 
126
        request.requiresExternalPower = false
-
 
127
 
-
 
128
        do {
-
 
129
            try BGTaskScheduler.shared.submit(request)
-
 
130
        } catch {
-
 
131
            print("Could not schedule processing: \(error)")
-
 
132
        }
-
 
133
    }
-
 
134
        
-
 
135
    func handleProcessTask(task: BGProcessingTask) {
-
 
136
        scheduleProcess()
-
 
137
        
-
 
138
        let syncAdapter = SyncAdapter()
-
 
139
        syncAdapter.sync { success in
-
 
140
            task.setTaskCompleted(success: success)
-
 
141
        }
-
 
142
 
-
 
143
        task.setTaskCompleted(success: true)
-
 
144
    }
-
 
145
        
-
 
146
    func handleRefreshTask(task: BGAppRefreshTask) {
-
 
147
        scheduleRefresh()
-
 
148
        
-
 
149
        
-
 
150
        
-
 
151
        let syncAdapter = SyncAdapter()
-
 
152
        if syncAdapter.isCheckChangesRequired() {
-
 
153
            syncAdapter.checkChanges(isForeground: false) { success in
-
 
154
                task.setTaskCompleted(success: success)
-
 
155
            }
-
 
156
        } else {
-
 
157
            task.expirationHandler = {
-
 
158
                task.setTaskCompleted(success: false)
-
 
159
             }
-
 
160
        }
-
 
161
        
-
 
162
 
-
 
163
        task.setTaskCompleted(success: true)
Línea 93... Línea 164...
93
    }
164
    }
Línea 94... Línea 165...
94
    
165
    
Línea 145... Línea 216...
145
        let dateFormatter = DateFormatter()
216
        let dateFormatter = DateFormatter()
146
        dateFormatter.dateFormat = Constants.FORMAT_DATE_YMD
217
        dateFormatter.dateFormat = Constants.FORMAT_DATE_YMD
Línea 147... Línea 218...
147
        
218
        
148
        let timeFormatter = DateFormatter()
219
        let timeFormatter = DateFormatter()
149
        timeFormatter.dateFormat = Constants.FORMAT_TIME_12
-
 
150
        /*
-
 
151
        let dateOn = dateFormatter.string(from: now)
-
 
152
        let timeOn = dateFormatter.string(from: now)
-
 
153
        
-
 
154
        let userNotificationDao = UserNotificationDao.sharedInstance
-
 
155
        var userNotification : UserNotificationModel
-
 
156
        
-
 
157
   
-
 
158
        if Config.DEBUG && !appData.userUuid.isEmpty {
-
 
159
            userNotification = UserNotificationModel(userUuid: appData.userUuid, title: "userInfo", body: "\(userInfo)", viewed: 0, url: "", dateOn: dateOn, timeOn: timeOn)
-
 
Línea 160... Línea -...
160
            
-
 
161
 
-
 
162
            userNotificationDao.insert(userNotification: userNotification)
-
 
Línea 163... Línea 220...
163
        }
220
        timeFormatter.dateFormat = Constants.FORMAT_TIME_12
164
         */
221