iOS app with Voice over IP background enabled not working properly in background on iOS 10

chuckctichuckcti USMember ✭✭
edited September 2016 in Xamarin.iOS

We have an app that has been working properly when receiving background audio and text messages in iOS versions since 8.1 (at least). The same app, even when rebuilt with latest XCode and Xamarin updates, is not receiving either on devices running iOS 10. (The project Deployment Target is set to 8.1). The "Voice over IP" and "Audio and AirPlay" flags are enabled in info.plist background modes. And the input stream (and output) Service Type is set to VoIP.

Below is how we create and connect initially. Under pre-iOS 10, the HandleInputEvent is fired whether in background or foreground mode, whenever data is available. But on iOS 10 it is only fired when in foreground. In fact, if any data has been sent while in background, the HandleEvents do fire when the app is brought into the foreground, as if the data has been buffered and the events queued up on the device.

Also, this all works properly when running on an iOS 10 simulator - the problem is only when running on actual hardware.

Is anyone experiencing any similar issues? We have customers that are needing this resolved soon, so would appreciate any help.

        lock (this)
        {
            CFReadStream readStream;
            CFWriteStream writeStream;

            didConnectEvent.Reset();
            CFStream.CreatePairWithSocketToHost(new System.Net.IPEndPoint(addr, port), out readStream, out writeStream);

            inputStream = ObjCRuntime.Runtime.GetNSObject<NSInputStream>(readStream.Handle);
            outputStream = ObjCRuntime.Runtime.GetNSObject<NSOutputStream>(writeStream.Handle);

            inputStream.ServiceType = NSStreamServiceType.VoIP;
            outputStream.ServiceType = NSStreamServiceType.VoIP;

            inputStream.OnEvent += HandleInputEvent;
            outputStream.OnEvent += HandleOutputEvent;

            outputStream.Schedule(NSRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); 
            inputStream.Schedule(NSRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); 

            outputStream.Open();
            inputStream.Open();

        }

    void HandleInputEvent(object sender, NSStreamEventArgs e)
    {
        if (e.StreamEvent == NSStreamEvent.EndEncountered)
        {
            Close();
        }
        else if (e.StreamEvent == NSStreamEvent.ErrorOccurred)
        {
            Close();
        }
        else if (e.StreamEvent == NSStreamEvent.OpenCompleted)
        {
            isConnected = true;
            didConnectEvent.Set();
        }
        else if (e.StreamEvent == NSStreamEvent.HasBytesAvailable)
        {
            try
            {
                ReadData();
            }
            catch
            {
            }
        }
        else if (e.StreamEvent == NSStreamEvent.HasSpaceAvailable)
        {
            Log("Input Socket HasSpaceAvailable");
        }
    }

Posts

Sign In or Register to comment.