How can an iOS app keep a TCP connection alive indefinitely while in the background?

后端 未结 4 866
名媛妹妹
名媛妹妹 2020-12-02 09:53

An iPhone app, connecting to a remote server via TCP. The use scenarios are:

  1. app (user) sends data to server and server responds data back.
  2. server mig
4条回答
  •  醉梦人生
    2020-12-02 10:37

    1.Create your socket with VOIP property like this

    [inputStream setProperty:NSStreamNetworkServiceTypeVoIP forKey:NSStreamNetworkServiceType] ;
    
    [outputStream  setProperty:NSStreamNetworkServiceTypeVoIP forKey:NSStreamNetworkServiceType] ;
    

    2.Add required background mode as "App provides Voice over IP services" in app.plist

    If your application in background mode the voip socket will not close. Using this socket with uilocal notification you can get.

    "If your application is not an original voip application app store will reject"

提交回复
热议问题