Android libraries/classes in Xamarin.IOS - c#

I'm new and currently working on a Xamarin.IOS app based on a Xamarin.Android app. I noticed that the Android native app does background tasks using a class called Service from Android.App and classes from Android.Support.V7.App and Android.Content. I'm just wondering if there's any similar solution for Xamarin.IOS, or do I have to do it completely from scratch?

From document Backgrounding in Xamarin.iOS,we know that:
In iOS, backgrounding is recognized as an application state, and apps
are moved in and out of the background state depending on the behavior
of the app and the user. iOS also offers several options for wiring an
app to run in the background, including asking the OS for time to
complete an important task, operating as a type of known
background-necessary application, and refreshing an application's
content at designated intervals.
IOS regulates background processing very tightly, and offers three approaches to implement it:
Register a Background Task
If an application needs to complete an important task, it can ask iOS not to interrupt the task when the application moves into the background. For example, an application might need to finish logging in a user, or finish downloading a large file.
Register as a Background-Necessary Application - An app can register as a specific type of application that has known, specific
backgrounding requirements, such as Audio , VoIP , External Accessory
, Newsstand , and Location . These applications are allowed
continuous background processing privileges as long as they are
performing tasks that are within the parameters of the registered
application type.
Enable Background Updates - Applications can trigger background updates with Region Monitoring or by listening for Significant
Location Changes . As of iOS 7, applications can also register to
update content in the background using Background Fetch or Remote
Notifications .
For more details, you can check:https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/introduction-to-backgrounding-in-ios.

Related

UWP: how to run a task without slowing down?

i'm developing an uwp app in c# capable to play midi files. I created a ThreadPoolTimer to scan a tick of 1 ms and other ThreadPool to run an async task that launch the midi messages of files relative to the time scanned by tick. It works correctly however when i do some other operation with laptop it throw a slow down behaviour. Mainly when i turn the gui in background. I changed the ThreadPool.RunAsync() with a Task.Run() and it works better but i'm trying to understand what is the best way to do a real time app with uwp because i need to implement new tasks. Additionally, i want to change base priority of my app programmatically because it works better with high priority but i don't want to change it manually everytime.
Ho can i do this tasks? i'm searching on internet but i not found any useful information about this in uwp.
Thank you
Edit: I want to use this app for play music so i need to develop it with high performance feature. For this cause i need to launch it directly with high priority level.
maybe can i develop some library

Microsoft.Phone.Scheduler.Alarm in a BackgroundTask

I recommend your assistance.
I am using Silverlight 8.1 to program an GPS based alarm app (Because the Microsoft.Phone.Scheduler.Alarm api is blocked in WP 8.1).
Now I am trying to create a BackgroundTask triggered by the GeofenceMonitor.
My problem is that a BackgroundTask must be located in a "Windows Runtime Component" project and you can't set the compilation target to Silverlight 8.1, so I cannot create an Alarm in there.
Is there a workaround or is it just impossible to launch an Alarm from a BackgroundTask?
I would appreciate every solution.
Unfortunately you cannot mix WinRT and WP8.1 Silverlight.
As you mentioned the Alarm API doesn't work with WP (so much for "universal") and the Silverlight Runtime doesn't have the GeofenceMonitor. You can have a Silverlight Project with a WinRT background task, but that won't get you anywhere.
I don't know if you want these alarms permanently associated with a location or rather short-lived, but maybe this would be a solution:
Configure your app to keep running in the background. There is a dedicated "LocationTracking" Execution Type that you can use for any app that tracks the GPS Position in the background (see this site for details).
You can then use the PositionChanged event of your Geolocator to check if you are within your fence and add an (almost) instant alarm.
const string id = "whateverYourIdIs";
var existing = ScheduledActionService.Find(id);
if(existing != null)
ScheduledActionService.Remove(id);
Alarm alarm = new Alarm(id)
{
BeginTime = DateTime.Now.AddSeconds(1),
Content = "You have reached your location!",
};
ScheduledActionService.Add(alarm);
If you don't want to keep your app running, you could (propably) launch another background task (SL) from within the geo-fencing background task (WinRT).

How location tracking is different than other background task?

In Windows Phone 8, it is suggested that, if I use LocationTracking as suggested in following code, my application will get location information continuously.
<BackgroundExecution>
<ExecutionType Name=”LocationTracking” />
</BackgroundExecution>
Now, Background Agent only executed after ~30 mins, and which is also with lots of limitations, like, it may run or may not run depending on OS.
How LocationTracking is different than Background Agent. Will it gives location every time location changes, or still it may invoke after 30 min.
Thanks.
As MSDN says:
On Windows Phone 8, a location-tracking app can continue to run in the background after the user navigates away, as long as the app continues to actively track location. This feature enables scenarios such as an app that provides turn-by-turn directions. For a walkthrough of creating a simple app that runs in the background, see How to run location-tracking apps in the background for Windows Phone 8.
There are also more differences and you must look out for API restrictions.
You can compare it with Background agent unsupported api.
And you should also be aware of some Additional requirements for specific app types.

BackGround Task not working in a window phone 8 beta app

I have created a Window phone 8 app. Which changes the lockscreen image and notification in around 30 sec randomly.
My code works well in the emulator and device. When I install it through the code. My problem is that when I have submitted the app to the store as a beta app. And now I install the app from the store the app don't work as it was working. The lockscreen content don't change it remains static. I have checked the settings background agents that app is running in the background tasks but not showing the result.
What could be the cause that app is running well from the code but not from the xap uploaded to the store.
Link of app is http://www.windowsphone.com/s?appid=00d47e34-a551-4c98-b2a6-32e10babdc2f
am I missing any capability that need to fixed.
Your suggestions are welcome.
Because your title says you are using a background task and you are trying to do something every 30 secs, I assume that you're using ScheduledActionService.LaunchForTest to trigger your background task and which then performs the updating.
ScheduledActionService.LaunchForTest is only supported in DEBUG builds as a way to aid testing. It is not possible to submit an app to the store that is built in DEBUG mode so this will not work.
It is not possible to create an app which will update so often in the background. To have such an app would, potentially, drain the battery really quickly and so provide a very poor experience to users.
The best you can do is to have the background agent run on a periodic schedule (approx. every 30 mins) or trigger the updates via push notifications. (But this wouldn't work for the lock screen image.)

Control application execution under any condition in WP8

I'm trying to build a basic tracking app for Windows Phone 8. However I can't figure out which model to use. The app shall log the location in a definable interval (e.g. 5 sec or even 2 hours).
If I develop the app as an foreground application the tracking will stop if the user opens another program, the screen locks (you can configure the app to continue running under the lock screen), or you reveice a phone call. Overall the risk of the app not being executed is to high.
There are also background tasks that are scheduled by the OS, and are only allowed to run a few seconds or minutes depending on the current state of the phone. Is there some workaround to schedule the background task execution as defined by the user? E.g. the Email client can be set to fetch emails every 15 minutes, therefore there must be some way.
The thrid option would be using the push notification service. This however seems stupid as some third party Microsoft server has to be involved and other limitations may apply. And more importantly, the app must run to receive the notification.
What is best practise on this? I don't care about battery drain as long as the app works as wanted. Similar solutions must exists for tiles that shall be updated more frequently (30 minutes or even more seems awfully long)? Am I missing something?
A basic app that can call it's own sleep would be great, but if it get's killed after a few seconds, that won't do it. Or does sleep time not count?
I'm afraid you can't do anything to make sure about your app execution.
Standard foreground application is always less important than things like incoming phone call, so you have to assume that it can be paused or stopped at any time. You also can't force user to use your app - that's why user is able to exit the app at any time.
Background execution on Windows Phone cannot be made permanent - that's how that OS is designed. And mail application is not a good example because it's a build in app. It was made as a part of that system, so it has another set of rules (if any).
I don't really see a way to do that using Push Notifications. But even if there is one, I'm sure it's not how that feature should be used.

Categories