Is it possible to keep a socket connected in background? (LongPolling)

DominikGanicDominikGanic DEMember ✭✭

Hi guys,

I'm writing an application in Xamarin.Forms which requires the current GPS coordinates each second to refresh them on other devices. I'm using SignalR as technology in my application, the transport protocol is LongPolling.

Is it possible to hold the socket connection alive even in background? On Android it seems to work fine so far, but when my iOS application enters background mode, the socket connection is like frozen.

How can I keep my socket connected in background?

Thanks a lot.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited July 3

    The categories which allowed to run in background

    • Audio
    • VoIP
    • External Accessories and Bluetooth
    • Location
    • Fetch (iOS 7+)
    • Remote Notifications (iOS 7+)

    Is it possible to keep a socket connected in background?

    I think it's impossible , apple does not allow networking task in background unless your app has some other reason to run indefinitely in the background.

  • DominikGanicDominikGanic DEMember ✭✭

    @ColeX said:
    The categories which allowed to run in background

    • Audio
    • VoIP
    • External Accessories and Bluetooth
    • Location
    • Fetch (iOS 7+)
    • Remote Notifications (iOS 7+)

    Is it possible to keep a socket connected in background?

    I think it's impossible , apple does not allow networking task in background unless your app has some other reason to run indefinitely in the background.

    Well, when Location fetch is allowed in background, am I allowed to send the fetched GPS coordinates with an webrequest in background?

    For example WhatsApp has "Live-Locations", when moving into background, the app still updates the current position live. That would be something that I need.

  • ColeXColeX Member, Xamarin Team Xamurai
  • DominikGanicDominikGanic DEMember ✭✭
    edited July 3

    So far, currently I've implemented the location manager successfully. This is pretty much the first step to my goal.

    I hope it's possible to submit webrequests now when location got fetched. Otherwise I could try to "reconnect" the socket and submit the GPS position.

    Will Apple check my code when I try to upload it on the app store? I'm about to include a webrequest / socket connection into the location manager in background.

    Btw.: Thanks a lot so far, for helping me out, to figure out the way how to create my algorithm!

    Update: My app is for a longer time now in background and keeps sending the current updated coordinates to my SignalR server.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited July 4

    Will Apple check my code when I try to upload it on the app store?

    Apple will not know your exact code but the network execution will be inspected when in background mode , you have to explain to apple why you wanna to do it.

Sign In or Register to comment.