Running background task when user stops using app and moved to another in Metro app - microsoft-metro

Hello I am having below requirement in my metro app. Can you please explain how to handle this?
User logged in to app by entering his login credentails.
Then user moved to another app and started working on it(still he is using machine).
He came back after 15 Min. Now, I have to throw error message say "Session Tiemout"
I tried using BackgroungTask - but not succeeded. Reason is I cant initiate background task OnSuspend().
Let me know how to implement this?

If you want the notification to happen when the app is activated again, then simply register the App Activation handler and check to see if your login has timed out.
If you want the notification to happen outside of your app you will need to use a toast notification with a scheduled notification.
Background tasks are for doing work in the background while the user is doing something else. It can't be used for notifications.

Related

Use Flutter Firebase Cloud Message (notification) to trigger background task to get current device location and make API call even on app terminated

When I get Only data FCM notification, I want to get person location and send it to my API in all app states: Foreground, Background, Terminated.
When app is in Foreground I have no problem.
When app goes to Background I am not able to get device location and make API call.
I did not even test terminated because I had no success in Background yet.
What I am using for test is:
FCM: firebase_messaging
To create background task: background_fetch
On notification received I am creating background task (NOTE: It will be created on background or terminated states in this states, not sure if this is true, most probably not I think.)
here is what I receive when trying in background
**Questions:
Is it possible?
What kind of solution can you suggest?
what is wrong in my solution**
Thanks in advance

Call status change web-service when my App is deleted

In my application , i works with web-services and when user log in into my app my app is sending a request with status 1 means loged in and when on log out button click sending a request with status 0.
Now problem is , when user removes app from devices , status in my server is remain 1(log in) , hence other user can see him available while his app is not in device. so is there any way by which i can send request when my app removes from device (i don't think it is possible) or is there any other way that i can do in my backend side ?
Thanks in advance.
It is not possible to call a web service when the user deleting the app from an ios device. There are three methods to came to know that whether your application is there in user's ios device. But there are few limitations also.
Activate Push notification: By doing this, device will get registered with Apple's push notification service. When user delete the app from device, the registration will be revoked from APNS server and through the APNS feedback service, you can get to know whether the application is existing. (Limitation: If the user did not agree with receiving push notifications, then the app will not be registered with APNS and you never came to know that whether application is existing or not)
Activate Location Based service: If your application enables location based service, then your application will get periodic location updates in a location delegate method. In this delegate, you can call a webservice and keep update the status of user even the application is in background. (Limitation: If user disables the location update, then your server will not get info about user status)
Periodically Call a Webservice From you app: This is possible only if your app is active. (Limitation: When you application pushed in to background, your application will be in suspended mode, so it will not possible to call webservice)
Sorry Unfortunately Apple not provide any method that user Uninstall app from user's device, There is no such method.
When user delete any application device does give the alert "Do you want to delete this application" with option "Delete" and "Cancel". You don't have to write any specific code for this.
I just assume that There is one method in which you can find out when user is about to delete your app. That is you need to implement push notification Apple server will inform you when you try to push to an uninstalled instance. Other than that there's no way to detect it but i am not sure its helpful or not.
You can't do this from within the app. You would want to do something like have a periodic task which runs on the backend, checking the last activity date of logged in users and setting them to 'not available' after some configured period of inactivity. This will probably require some changes to the backend to record last activity date and a change to the app so that while it's open it sends a periodic 'heartbeat' to the backend. You probably want to make the timeout quite big (say 15 minutes, big enough to not have a large impact on performance).

How to get local notifications when app enters the background

I am new to iphone. I am doing Project in that i have struck in the middle because of local notifications concept.In my applications i am sending the request to the server and getting response for every 20 sec by using timer concept but when the application enter the background
how can we get the response from the server for every 20 sec by using local notifications.If anybody knows this concept please help me...
When App on background mode , you receive loacl notification, and you click yes button then
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
this function is call and you get dictionary
NSLog(#"%#",[notif userInfo]);
and call the xml in this function.. and you can get resonance from your server very easily
Generally, your app doesn't get to execute in the background, and local notifications won't provide you the ability to execute in the background.
(There are exceptions to this, but they come with limitations. If you really need to ping a server every 20 sec because you're something like a VoIP app, you can declare that you're a VoIP app and set up a keep-alive handler for doing that ping. However, if you're submitting to the App Store, Apple will require that you're really implementing a VoIP-like app, and not just downloading new RSS feeds in the background or some such.)
What local notifications are for is getting the user's attention when your app isn't active. While your app is running, you can schedule a local notification to post a message to the user some time later (sort of like a calendar alarm). If you're using one of the supported background execution modes, you can use a local notification to get the user's attention right now. Either way, your app only gets activated if the user chooses to tap the notification.

Check user location before they see Push Notification Message?

Would someone happen to know a small code sniplet to get and compare the users location before they see a push message inside the appDelegate class?
If the app isn't running, then you can't 'get in the way' the message will be displayed to the user. And where I say running I mean in the foreground and with the screen on.
If the app is running, then you can embed arbitrary information (such as a relevant location) with the push notification payload. When this is delivered to your app's delegate, you can check for their location as you normally would, and if the user is where you'd like them to be you can pop up a message to them.
It seems like a lot of hard work for people that are actually using the app at the time that the notification is delivered though. What will you do about all the users who aren't running the app and get the push notification popup without the check?

Push Notifications not opening app "With Options" if its not clicked immediately when its presented

I am running into a problem here. I am able to receive, capture and save an APNS message just fine if I do it while my app is running or if I click "View" when it comes in if the app is closed.
The problem I am running into is.. If the app is NOT running and I receive a APNS message and chose to look at it later by selecting "Close"... the next time I open the app, the app is not opening "with options". Therefor, the APNS message is lost. The same thing happens if the screen lock comes on before "viewing" the APNS message.
How do I handle this?
Thanks in advance!
Don’t assume that push notifications will make it to your app—their delivery isn’t guaranteed, even if the user doesn’t “close” the alert a notification brings up. Your server should have the authoritative state of whatever notifications your app needs to display when it launches, and the app should check that state regardless of whether it’s launched from a notification or not; one reason for this is that if your app receives multiple notifications while in the background, only one of those notifications will get delivered to the app when the user chooses to view it.