Warm tip: This article is reproduced from stackoverflow.com, please click
apple-push-notifications background voip ios13 enterprise

iOS13: Alternative to VOIP push notifications (enterprise) to silently communicate with an app in ba

发布于 2020-04-08 15:42:17

So for about 4 years in our enterprise environment we were happily using VOIP push notifications to remotely access user's tablets for maintenance and remote data repair purposes. Unlike regular APNS, VOIP push notifications would access the app even if weren't running. I should have figured apple would kill it sometime.

Is anyone aware of a private API to bypass the pushkit requirement to call reportNewIncomingCallWithUUID which brings about a full screen call UI, or another mechanism that I can't think of to access an app in the background even if killed - Notification Service Extensions won't work (I believe) because it will only work for screen messages. Thanks

Questioner
Nostradamus
Viewed
38
pepsy 2020-02-01 01:50

If you are not going to publish it to the Apple store, and don't care about the use of private API (which can change anytime, breaking your code), you can use method swizzling to change the implementation of the function that's called by the system to crash the app.

In my case, I have a project with swift and objc interoperability. I did it this way:

  • Create a file named PKPushRegistry+PKPushFix_m.h with the contents of this gist.
  • Include it in your swift bridging header.

Other options are building it with Xcode 10, or manually overriding iOS SDK 13 from an Xcode 11 with a copy of iOS SDK 12.


Here's the content of the gist, in case it becomes unavailable in the future:

#import <objc/runtime.h>
#import <PushKit/PushKit.h>

@interface PKPushRegistry (Fix)
@end

@implementation PKPushRegistry (Fix)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];

        SEL originalSelector = @selector(_terminateAppIfThereAreUnhandledVoIPPushes);
        SEL swizzledSelector = @selector(doNotCrash);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

        // When swizzling a class method, use the following:
        // Class class = object_getClass((id)self);
        // ...
        // Method originalMethod = class_getClassMethod(class, originalSelector);
        // Method swizzledMethod = class_getClassMethod(class, swizzledSelector);

        BOOL didAddMethod =
            class_addMethod(class,
                originalSelector,
                method_getImplementation(swizzledMethod),
                method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                swizzledSelector,
                method_getImplementation(originalMethod),
                method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
        [super load];
    });
}

#pragma mark - Method Swizzling

- (void)doNotCrash {
    NSLog(@"Unhandled VoIP Push");
}

@end