kCFStreamNetworkServiceTypeVoIP is deprecated in iOS 9.0
To whom it may concern,
I got the following warning message when upgrading to Xcode 7.0 and the development target 9.0.
'kCFStreamNetworkServiceTypeVoIP' is deprecated: first deprecated in iOS 9.0 - use PushKit for VoIP control purposes" in GCDAsyncSocket.m
Please let me know if you need more detail to resolve this issue.
Thank you for precious time on this.
+1
+1
+1
Please be constructive and discuss possible solutions instead of just adding a +1
Thank you!
How about switch it to kCFStreamNetworkServiceTypeVoice instead of VOIP?
From my reading of the situation, this has nothing to do with VOIP, but rather a hack to keep certain streams open when your app goes to the background. For folks that want this, have you tried testing your app with the current codebase to see if the sockets already stay open in the background? (if your code is even calling enableBackgroundingOnSocket). The next obvious replacement is another constant from that header, kCFStreamNetworkServiceTypeBackground, although I haven't tested it myself. (My app already stays open in the background when a light show is running via the network, for other reasons related to audio.) Considering how Apple loves to police which apps are allowed to operate in the background (and categorize them under specific exceptions within the entitlements file) I encourage you to go the official route, rather than relying on a hack that will likely be cut off at the worst possible time for you and anger any users affected by the lack of backgroundability you may not be able to fix. If you don't have the proper entitlements approved, in the long run, no CF hack is going to save you. Hope this helps. Again, I didn't dig too deep on this yet, but wanted to throw in my 2 cents.
`#import <PushKit/PushKit.h> .......
r1 = CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, PKPushTypeVoIP);
r2 = CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, PKPushTypeVoIP);`
Good replacement, @pengyanb, however this would only work on iOS, as the PushKit framework is not available on tvOS (and not sure about OS X).
@pengyanb Thanks for your code !
I don't think this "solution" makes any sense at all.
PKPushTypeVoIP is a "push type" used with PushKit, as one of the values that can go in desiredPushTypes when registering yourself with the PKPushRegistry, in order to register for "VoIP pushes" in iOS 8+ (https://developer.apple.com/videos/wwdc/2014/ Writing Energy Efficient Code, Part 2, starting 36:20), for apps with "voip" background mode.
kCFStreamNetworkServiceTypeVoIP is a CFStream "network service type" that is meant to mark a stream as not to be closed when going into the background, for apps with the "voip" background mode, so that they can receive and wake up in response to (potentially VoIP) network traffic on that stream, which is important because normal streams get closed when going into the background. These two things are from two completely different universes and don't have anything to do with each other.
Apple deprecated kCFStreamNetworkServiceTypeVoIP (as well as the -[UIApplication setKeepAliveTimeout:handler:] method, which was also used for "voip" background mode apps to allow a periodic message to the server) in iOS 9 presumably because they want people to use VoIP pushes instead of keeping a network stream open or sending keep alives. The idea would be that there is no longer any need to keep network streams open to wait for traffic, because VoIP pushes are guaranteed to wake your app, even if it was killed. The documentation for the -[UIApplication setKeepAliveTimeout:handler:] method specifically says in iOS 8+ to use remote notifications instead of the method, because remote notifications eliminate the need to check in with your server; the same thing applies to the network service type.
Good point. I wonder what the alternative would be for SIP/voip applications that cannot use remote notifications due to no internet connectivity.
@janiduw Isn't SIP/VOIP using internet/network connectivity by default? Then there is always a connection for remote notifications. In case there is no network connection, making calls isn't possible, so no problem if the remote notification isn't received too.
The docu in the GCDAsyncSocket header from - (BOOL)enableBackgroundingOnSocket mentions:
Configures the socket to allow it to operate when the iOS application has been backgrounded. In other words, this method creates a read & write stream, and invokes:
CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP); CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
This seems just an option to keep the socket open when the app is in background. It doesn't seem to be specifically for VOIP, only the VOIP constant is chosen in the code. For any background purpose, the app should have the Background Mode capability enabled in the target settings, with the appropriate mode(s) selected. One of the modes is VOIP, another is background fetch.
For the purpose of AsyncSocket, wouldn't background fetch be more appropriate than VOIP?
Since our app doesn't use Background modes at all, we have replaced kCFStreamNetworkServiceTypeVoIP by kCFStreamNetworkServiceTypeBackground to suppress the Xcode warnings.
For those who use CocoaPods, I thought I'd share an excerpt of my Podfile, that does the suggested replacement by @funnel20 in the post_install.
Dir.glob(File.join('Pods/CocoaAsyncSocket/', "**/*.{h,m}")).each do |file|
contents = File.read(file)
patched = contents.gsub('kCFStreamNetworkServiceTypeVoIP', 'kCFStreamNetworkServiceTypeBackground')
if Regexp.last_match
FileUtils.chmod "u=wr", file
File.write(file, patched)
puts "Patched '#{file}'."
end
end
This commit in latest version 7.6.4 suppresses the warning, but doesn't provide a robust future-proof solution.
Unfortunately, as far as I'm aware, there is no workaround. You must migrate to PushKit instead, which is out of scope of the goals of CocoaAsyncSocket.
@chris Suppressing the deprecation warning in your latest commit is a work-around. But no solution, in case Apple removes the constant from a future update, the code might crash.
What about my proposed solution https://github.com/robbiehanson/CocoaAsyncSocket/issues/361#issuecomment-326593194 ?
@funnel20 It looks like it won't give equivalent behavior to the old flag, however it's probably the right way forward given the deprecation and Apple's insistence on migration to PushKit. Please submit a pull request request and make sure the documentation string is updated. Thanks!
@chrisballinger Sorry for the delay, but pull request is available now at #717