7 Replies
      Latest reply on Aug 23, 2019 12:39 AM by eskimo
      Tim8872 Level 1 Level 1 (0 points)

        Hello,

         

        I want to create a TCP sockets, which runs also in background. For example if the dispaly is switched off.

        Currently my socket will be instantly closed, if display is off (same if I minimize the app).

         

        What possibilities we have to create this special socket on iOS?

         

        My background: I built a special VoIP app, which holds all the time a connection to the server.

        There is a heartbeat mechanism which checks cyclic the connection between client and server.

         

        Many thanks in advance!

        • Re: Background TCP socket (iOS)
          eskimo Apple Staff Apple Staff (11,825 points)

          It’s perfectly feasible to run a TCP connection in the background, you just have to prevent your app from being suspended.  Technote 2277 Networking and Multitasking describes the rules of the road here.

          You wrote:

          I built a special VoIP app, which holds all the time a connection to the server.

          There’s no good way to do this on iOS.  Historically the legacy VoIP API used to work this way, but that mechanism has long since been deprecated (and for good reason; it never worked reliably).  Modern VoIP apps have migrated to PushKit, and that’s what I’d recommend you do here.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: Background TCP socket (iOS)
              Tim8872 Level 1 Level 1 (0 points)

              Many thanks for your fast reply!

               

              "Modern VoIP apps have migrated to PushKit, and that’s what I’d recommend you do here."

              Is it possible to use PushKit in closed networks? If not, what is an alternative for PushKit?

                • Re: Background TCP socket (iOS)
                  eskimo Apple Staff Apple Staff (11,825 points)

                  Is it possible to use PushKit in closed networks?

                  Not if the network is completely closed.  However, it doesn’t take much to open the network up enough for devices to open the outgoing connection required to make push notifications work, and that’s by far the easier best to this problem.

                  If not, what is an alternative for PushKit?

                  There aren’t any good alternatives.  My advice, as stated in QA1938, is to contact DTS officially and discuss this with the DTS engineer who’s taken the lead on VoIP issues (which, for once, is not me :-).

                  Please make sure to reference this DevForums thread in your support request.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"

                    • Re: Background TCP socket (iOS)
                      Tim8872 Level 1 Level 1 (0 points)

                      Okay, many thanks for answers.

                       

                      "However, it doesn’t take much to open the network up enough for devices to open the outgoing connection required to make push notifications work, and that’s by far the easier best to this problem."

                       

                      Could you say me which protocols or ports I need for this use case?

                       

                      Exist for PushKit a WWDC video or something else?

                        • Re: Background TCP socket (iOS)
                          eskimo Apple Staff Apple Staff (11,825 points)

                          Could you say me which protocols or ports I need for this use case?

                          This is documented by Apple Support in this article.

                          Exist for PushKit a WWDC video or something else?

                          It was introduced in WWDC 2014 Session 712 Writing Energy Efficient Code, Part 2.  Honestly though, the API is pretty simple, and is reasonably well covered by the official PushKit docs.

                          One significant change in iOS 13 beta is that the system now requires that apps using PushKit generate a CallKit call for every push notification they receive.  This is a new change, and one that I’m not really up to speed on (did I mention that I’m not DTS’s VoIP specialist? :-).  The announcement was in WWDC 2019 Session 707 Advances in App Background Execution but you can find more info in this thread.

                          Share and Enjoy

                          Quinn “The Eskimo!”
                          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                          let myEmail = "eskimo" + "1" + "@apple.com"

                            • Re: Background TCP socket (iOS)
                              Tim8872 Level 1 Level 1 (0 points)

                              "It was introduced in WWDC 2014 Session 712 Writing Energy Efficient Code, Part 2"

                              Sorry, but this link doesn't work.

                               

                              "The announcement was in WWDC 2019 Session 707 Advances in App Background Execution but you can find more info in this thread."

                              Thanks a lot!

                                • Re: Background TCP socket (iOS)
                                  eskimo Apple Staff Apple Staff (11,825 points)

                                  this link doesn't work.

                                  Indeed.  Sorry about the bogus link.  The Powers That Be™ have decided that the world would be a better place if we removed old WWDC videos.  On the plus side, the PushKit docs are in good shape.

                                  Share and Enjoy

                                  Quinn “The Eskimo!”
                                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                                  let myEmail = "eskimo" + "1" + "@apple.com"