Xamarin iOS - SignalR stops receiving messages in background mode - c#

Currently i am developing an app which needs to be capable of receiving and interacting based on realtime event notifications from all platforms. We are using SignalR to achieve so. I am using Xamarin.Forms as this is a shared project.
Right now everything is working fine especially android is perfect. No matter application is in background or foreground its receiving messages from SignalR and playing sound and vibrates as expected. In iOS 10.3 simulator also its working as expected. Untill yesterday when i realized in real device when application goes in background mode it pauses everything and when its back in foreground it resumes as its supposed to be doing and as if the notification was sent just now. So i did some research and thought i would perform a long running task (in my case a forever loop with a 10seconds interval) in the background thread and in that way i was able to receive signalr messages (which i can see on the debugger) and vibration was playing while being in background. But after a certain time i am guessing within 10 mins iOS is clearing up its memory and when i open the app it seems reloaded because it shows the login screen instead of where i left the app.
Now question is:
1. How can i keep receiving SignalR events while being in background?
2. How can i stop iOS to reload my app due to being in background for a long time?
3. The app has to be Appstore publishable as in appstore must not reject it due to some dodgy works being done in the background like playing silent audio forever or using VoIP for background since this is not a VoIP app.
4. Also soon i am gonna be implementing location update in background mode so is this gonna keep the whole app alive in background? And behave like i am expecting?
As i am currently travelling i can not provide any code snippet but any questions please feel free to ask.
Thanks for your help and reading this boring article.

Just in case if someone is facing similar issue.
Apple doesnt allow to execute your app unless it falls in certain category Look at table 3-1. Fortunately, I had a valid reason to use continuous location update in foreground and background therefore as soon as I implemented location update event all my problems were solved immediately.
How to implement location update? Location DependencyService example for Xamarin.Forms
Hope that will help.

Related

Make Cortana Skill listen longer

at the moment I am developing a Cortana skill with .net & C# and MS-BotFramework, which should primarily run on the Invoke from Harman.
So far everything fits. However, I would like to increase the time the skill listens.
So far I have only found one way for UWP to increase this time (https://learn.microsoft.com/de-de/windows/uwp/design/input/set-speech-recognition-timeouts). Unfortunately, this doesn't help me with my Cortana skill - because I want to deploy it as a Cortana skill and not as an UWP app.
Now my question: Is there generally a way to increase the time the Cortana skill waits for an answer from the user?
Thanks for help!,
PG
Unfortunately the skill does not control the timeout or interaction time with the Cortana channel (the app.) I have worked around this by setting up async timer tasks that use replaceDialog to change the dialog flow, and/or prompt again. Unfortunately, dialog flow works a bit differently in C# (so I do not have an example). However, on Invoke, reprompts happen automatically. On Windows 10/Mobile, because there is a card, they don't (as the card should still be visible). Please add the suggestion to add this feature via the feedback hub (via Windows start/search menu). Please also send me a note if you want to continue the discussion.

Windows 10 uwp sticky background service?

I'm trying to convert an Android app to Windows 10 UWP. On android its easy: when boot completed, app service is started. It connects to controller over internet, fetches system state and all data (temp sensors, pumps, valves, etc) and keeps everything in memory. Foreground app can get data as soon as service gets them and display values, charts realtime. After closing foreground app, service keeps working, I still have all system state and I can play alarm sound if needed.
Is it possible to do [almost] same functionality on Windows 10 uwp?
I cannot find a way to start service with windows. Service started with foreground app is stopped when foreground app is closed. SocketBackgroundTask keeps connection perfect, but system state is lost with service.
Should I save system state to file and analyze all data after each renew? Data flow varies from once in 10 minutes to ~10 per second.
Or should I forget Windows 10 as limited platform?
I am designing a similar piece of sensor control software, and I have found UWP/Win10 to be limiting. We ultimately resorted to using Assigned Access to keep the app permanently in the foreground.
Assigned Access
Assigned access assigns an app to an account. So when Mr. Bob logs in, the app starts full-screen, and it cannot be closed, and if it crashes, it is restarted.
Note that the only way to access other parts of the system is to hit ALT-CTRL-DEL and log in as a different user. That might be bad for some, but if you have critical process monitoring going on, then it's probably a good thing that the user can't mess about with the system or quit the app.
It's also quite simple to implement, you only need to add a declaration to the app manifest, and you need Win10 Pro or Higher.
Windows IoT
You could also look at Windows 10 IoT, when you deploy an app to it, it does pretty much the same thing. However the range of hardware is quite limited, and many of them aren't fully functional yet - RPi suffers from SDcards being inherently unreliable, and lack of graphics acceleration. Dragonboard lacks driver support for resolutions other than 720p, etc. https://developer.qualcomm.com/forum/qdn-forums/hardware/iot-development-platform/29652
Extended Execution
In addition we have experimented with using extended execution, which lets the app run in minimised state, potentially indefinitely. I have mixed feelings about it. Although the app will keep running most of the time, but if the OS is struggling for resources, the app will get suspended and won't be restarted until the user switches back to it.

Debugging by attaching a process for windows phone apps

I'm currently running VS2013 Update 3, I'm building an app and i;m trying to mimic the Rate My App that shows up rate message dialog in b/w specified intervals.
My problem is that i've made a setting using ApplicationData.current.loclasettings and it is an integer.
and i want to see the settings number being updated every time i close and run the app to ensure the logic is perfect.
but i'm unable to do it. Every time i deploy the app from vs it replace the original app and thus erasing all the settings that have been previously saved.
I've tried to use attach a process but it doesnt work on windowsphones.
Well after a bit of research and going through the documentation it is clear that there is no way you can attach a process to the app that is already running on the phone.
At least for me there was no other way because Microsoft kept the USB debugging thing a little bit undocumented or not documented at all.
So, who ever are looking forward to first launch the app on a connected windows phone and then start the the connect to a process and select the appropriate device for communication , story it is not possible, at least the build that i;m using doesn't support. may there might be a better solution in the future.

WP8 AudioPlaybackAgent bug?

I have a problem with playing audio tracks with the AudioPlaybackAgent on devices running WP8. It works perfectly on WP7, but not on WP8. It only works sometimes for WP8, so there is no clear steps on how to reproduce it either. What seems to be the problem is that when a new track is about to play and I have set the BackgroundAudioPlayer.Instance.Track to the new AudioTrack, it don't receive onPlaystateChanged.TrackReady.
Why is this? I don't receive onError either.
Is there a known bug with playing audio on WP8 devices? It happens about 50% of the time, and the same track can both work and not work. What can be the problem here? Please help. Any from Microsoft that can help on this? That would be highly appreciated.
The fact this occurs 50% of the time makes me suspect this could be a race condition which didn't occur on WP7.
Are you doing any thread-locking (using Mutex, lock() etc) from your background agent when changing tracks? I had something similar for a WP8 background audio app that was previously working on WP7 and traced it back to a deadlock in my code.
Don't forget that WP8 now has dual-core processors and is more likely to hit such issues. See this post from someone on the Windows Phone team about back-compat between WP8 and 7. Especially interesting is the section named "Runtime behavior changes" in that post.

Disable Application from sleeping in Windows 8 Metro

I am working on an app which displays videos and am running into an issue where the machine goes to sleep after hitting the sleep time limit while a video is playing. Is there a way to disable this behavior in a Windows 8 Metro application?
You should use the DisplayRequest class, specifically DisplayRequest.RequestActive for this purpose. You must also remember to call DisplayRequest.RequestRelease once you are done to allow the display to sleep, for example, if you are not actively playing the movie, or in a menu screen, etc.

Categories

Resources