Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 19 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 19 Rev 21
Línea 14... Línea 14...
14
    
14
    
15
    @StateObject private var appNavigation = AppNavigation()
15
    @StateObject private var appNavigation = AppNavigation()
16
    @StateObject private var networkMonitor = NetworkMonitor()
16
    @StateObject private var networkMonitor = NetworkMonitor()
Línea 17... Línea 17...
17
    @State private var showToast : Bool = true
17
    @State private var showToast : Bool = true
18
    
18
    
19
    private var appData = AppData.sharedInstance
19
    private var appData = Environment(\.appData).wrappedValue
Línea 20... Línea 20...
20
    private var localNotification = LocalNotificationManager()
20
    private var localNotification = LocalNotificationManager()
21
    
21
 
22
 
22
 
Línea 178... Línea 178...
178
                    appData.save()
178
                    appData.save()
179
                }
179
                }
180
            }
180
            }
Línea 181... Línea 181...
181
 
181
 
182
        }
182
        }
183
        /*.onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_DEVICE_REGISTER_NAME))
183
        .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_DEVICE_REGISTER_NAME))
184
        { data in
184
        { data in
185
            if data.userInfo != nil {
185
            if data.userInfo != nil {
186
                let userInfo = data.userInfo!
186
                let userInfo = data.userInfo!
Línea -... Línea 187...
-
 
187
                let new_uuid = userInfo["uuid"] as? String ?? ""
187
                let new_uuid = userInfo["uuid"] as? String ?? ""
188
                
188
                
189
                
-
 
190
                
Línea 189... Línea 191...
189
                
191
                if !new_uuid.isEmpty {
190
                if !new_uuid.isEmpty {
192
                    if appData.deviceUuid != new_uuid {
191
                    if appData.deviceUuid != new_uuid {
193
                        print("Register Device Notification : \(new_uuid)")
Línea 192... Línea 194...
192
                        
194
                        
193
                        var sync = SyncModel()
195
                        var sync = SyncModel()
-
 
196
                        sync.data = new_uuid
-
 
197
                        sync.type = Constants.SYNC_ADAPTER_TYPE_DEVICE
194
                        sync.data = new_uuid
198
                        
195
                        sync.type = Constants.SYNC_ADAPTER_TYPE_DEVICE
199
                        let syncDao = SyncDao()
Línea -... Línea 200...
-
 
200
                        let syncID = syncDao.insert(record: sync)
196
                        
201
                        
197
                        let syncDao = SyncDao()
202
                        if syncID > 0 {
198
                        if syncDao.insert(record: sync) > 0 {
-
 
199
                            appData.deviceUuid = new_uuid
-
 
200
                            appData.save()
203
                            appData.deviceUuid = new_uuid
-
 
204
                            appData.save()
-
 
205
                            
-
 
206
                            sync.id = syncID
-
 
207
                            let syncAdapter = SyncAdapter()
-
 
208
                            syncAdapter.registerDevice(record: sync);
-
 
209
                        }
-
 
210
                    } else {
-
 
211
                        var sync = SyncModel()
-
 
212
                        sync.data = new_uuid
-
 
213
                        sync.type = Constants.SYNC_ADAPTER_TYPE_DEVICE
-
 
214
                        
-
 
215
                        let syncDao = SyncDao()
-
 
216
                        let syncID = syncDao.insert(record: sync)
-
 
217
                        
-
 
218
                        if syncID > 0 {
201
                            
219
 
202
                            let syncAdapter = SyncAdapter()
220
                            sync.id = syncID
203
                            syncAdapter.sync(isForeground: true) {
221
                            let syncAdapter = SyncAdapter()
204
                                success in
222
                            syncAdapter.registerDevice(record: sync);
205
                            }
223
                        }
206
                        }
224
                        
207
                    }
225
                    }
208
                }
226
                }
209
            }
227
            }
Línea 210... Línea 228...
210
        }*/
228
        }
211
        .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_FCM_REGISTER_NAME))
229
        .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_FCM_REGISTER_NAME))
-
 
230
        { data in
212
        { data in
231
            if data.userInfo != nil {
213
            if data.userInfo != nil {
232
                let userInfo = data.userInfo!
214
                let userInfo = data.userInfo!
233
                let token = userInfo["token"] as? String ?? ""
215
                let token = userInfo["token"] as? String ?? ""
234
                
216
                
235
   
217
   
236
                if !token.isEmpty {
218
                if !token.isEmpty {
237
                    if appData.fcmToken != token  {
219
                    if appData.fcmToken != token  {
238
                        print("Register FCM Notification : \(token)")
-
 
239
                        
-
 
240
                        var sync = SyncModel()
220
                            
241
                        sync.data = token
221
                        var sync = SyncModel()
242
                        sync.type = Constants.SYNC_ADAPTER_TYPE_FCM
Línea 222... Línea 243...
222
                        sync.data = token
243
                        
Línea 223... Línea 244...
223
                        sync.type = Constants.SYNC_ADAPTER_TYPE_FCM
244
                        let syncDao = SyncDao()
224
                            
245
                        let syncID = syncDao.insert(record: sync)
-
 
246
                        if syncID > 0 {
225
                        let syncDao = SyncDao()
247
                            sync.id = syncID
226
                        let syncId = syncDao.insert(record: sync)
248
                            
227
                        if syncId > 0 {
249
                            appData.fcmToken = token
228
                            appData.fcmToken = token
250
                            appData.save()
229
                            appData.save()
251
                            
Línea 300... Línea 322...
300
            var userNotification : UserNotificationModel  = UserNotificationModel(userUuid: appData.userUuid, title: title, body: body, viewed: viewed, url: url, command: command, dateOn: dateOn, timeOn: timeOn)
322
            var userNotification : UserNotificationModel  = UserNotificationModel(userUuid: appData.userUuid, title: title, body: body, viewed: viewed, url: url, command: command, dateOn: dateOn, timeOn: timeOn)
Línea 301... Línea 323...
301
                
323
                
-
 
324
                
-
 
325
 
302
                
326
            userNotificationDao.insert(userNotification: userNotification)
Línea 303... Línea 327...
303
 
327
        }.onAppear {