Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iOS 16 crash by kCFStreamNetworkServiceTypeVoIP #804

Closed
wants to merge 1 commit into from

Conversation

seasonZhu
Copy link

Fix iOS 16 crash by deprecated API, kCFStreamNetworkServiceTypeVoIP is deprecated, use PKPushTypeVoIP in PushKit.
I see this PR 802, use kCFStreamNetworkServiceTypeBackground replace kCFStreamNetworkServiceTypeVoIP.

I fix the crash by use 802 code.

In my App, I user CocoaMQTT, and it depend CocoaAsyncSocket, my App crash when mqtt begin to connect:

Linked against modern SDK, VOIP socket will not wake. Use Local Push Connectivity instead

libsp.dylib`spd_checkin_socket.cold.1:

  0x221e28364 <+0>: adrp  x8, 141901

  0x221e28368 <+4>: adrp  x9, 0

  0x221e2836c <+8>: add  x9, x9, #0xa3f      ; "Linked against modern SDK, VOIP socket will not wake. Use Local Push Connectivity instead"

  0x221e28370 <+12>: str  x9, [x8, #0x400]

-> 0x221e28374 <+16>: brk  #0x1

So I read Foundation code what‘s wrong with kCFStreamNetworkServiceTypeVoIP

/* deprecated network service type: */

CFN_EXPORT const CFStringRef kCFStreamNetworkServiceTypeVoIP       CF_DEPRECATED(10_7, 10_11, 4_0, 9_0, "use PushKit for VoIP control purposes");   // voice over IP control - this service type is deprecated in favor of using PushKit for VoIP control

kCFStreamNetworkServiceTypeVoIP is deprecated, and issues 402 mention.

Add #import to GCDAsyncSocket.m
#import <PushKit/PushKit.h>

Replace in enableBackgroundingOnSocketWithCaveat
r1 = CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, PKPushTypeVoIP); r2 = CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, PKPushTypeVoIP);

Then I use PKPushTypeVoIP replace kCFStreamNetworkServiceTypeVoIP.

Great, it’s OK now.

…s deprecated, use PKPushTypeVoIP in PushKit.
@funnel20
Copy link

This PR seems to solve the same issue as PR #802 but in a different way (by using PushKit). This PR only solves the issue partially, since there are more occurrences of kCFStreamNetworkServiceTypeVoIP throughout the project, as indicated in #802 .

@@ -8200,8 +8201,8 @@ - (BOOL)enableBackgroundingOnSocketWithCaveat:(BOOL)caveat

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
r1 = CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -8200,8 +8201,8 @@ - (BOOL)enableBackgroundingOnSocketWithCaveat:(BOOL)caveat

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
r1 = CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
r2 = CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amiraion
Copy link

@funnel20 Please review the PR and merge into master.

@seasonZhu

@funnel20
Copy link

funnel20 commented Jan 16, 2023

@amiraion Do we agree that kCFStreamNetworkServiceTypeBackground is the way to go (based on #802 )?

If not, I would like to mention that the proposed solution of @seasonZhu of using PushKit constant PKPushTypeVoIP has a different data type:

Apple docu on kCFStreamNetworkServiceTypeBackground:

const CFStringRef kCFStreamNetworkServiceTypeBackground;

Apple docu on PKPushTypeVoIP :

const PKPushType PKPushTypeVoIP;

Where PKPushType is:

typedef NSString *PKPushType;

This is CFStringRef vs. NSString, so it seems appropriate to use kCFStreamNetworkServiceTypeBackground as value for kCFStreamNetworkServiceType.

@github-actions
Copy link

This pull request has been marked as stale, it will be closed automatically if there is no further activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants