Post

Replies

Boosts

Views

Activity

Local Notification not working in Background Mode
I have implemented chat functionality in my app, as remote notifications are not possible to send from server side, i am using local notification to alert the user of new incoming message. Everything works fine in simulator, i can see notifications are displayed in foreground as well as background mode. But when i run the app on device, notification are only working in foreground mode. When app is in background, notifications wont show. After investigating this issue i found that they work fine when app is running in debug mode(i.e. launched from Xcode and cable still attached). But as soon as i disconnect the cable, they wont show anymore. Below is the code i have tested, both the code produces the same result. (FYI: It's a Xamarin.IOS app) code-block UILocalNotification localNotification = new UILocalNotification(); localNotification.FireDate = NSDate.Now; localNotification.TimeZone = NSTimeZone.DefaultTimeZone; localNotification.AlertBody = message; localNotification.SoundName = UILocalNotification.DefaultSoundName; localNotification.UserInfo = dict; UIApplication.SharedApplication.ScheduleLocalNotification(localNotification); code-block var content = new UNMutableNotificationContent(); content.Body = body; content.Sound = UNNotificationSound.Default; var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(1, false);				var requestID = "Chat"; var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger);				// schedule it UNUserNotificationCenter.Current.AddNotificationRequest(request, (error) => { if (error != null) { Console.WriteLine($"Error: {error.LocalizedDescription ?? ""}"); } else { Console.WriteLine("Scheduled..."); } });
2
0
4.1k
Jun ’20
ReloadData wont works as TableView.Window is nil (UITableViewAlertForLayoutOutsideViewHierarchy)
I have a TabBar controller with 4 tabs, all the controller are embedded in Navigation Controller. On the 4th tab there is ViewControllerA which is push to ViewControllerB using embedded navigation controller. Now ControllerB has tableview which gets updated from async service call made every 5 seconds. I am saving the response in database and reloading tableview.  when the user go back to ControllerA and come back to ControllerB, at this point i am reloading the tableview in ViewDidLoad from the saved data in database. Until this point everything works as expected. Tableview is refreshed with new data. But when i get new data from service and try to reload data at this point my CellForRowAtIndexPath breaks and wont reload the table. While trying to recreate this issue I got this UITableViewAlertForLayoutOutsideViewHierarchy. After testing this numerous time, i found out that ReloadData is not working as my TableView.Window is nil. After doing some research i tried the suggested solution like reloading data in ViewDidAppear, wrapping up ReloadDate in DispatchQueue.Main, LayoutIfNeeded but nothing seems to work. I don't know how the tableview is removed from view hierarchy after the reload data is called from ViewDidLoad.  Tableview is still visible but it just wont refresh anymore. But now if I going back to ControllerA and coming back to ControllerB, it will reload the tableview as latest data in fetched from database but again trying to update from server response will create the same issue. Not sure how TableView.Window becomes nil.
5
0
1.5k
Jun ’20