iOS13: Alternative to VOIP push notifications (enterprise) to silently communicate with an app in background now that iOS13 killed it

和自甴很熟 提交于 2020-12-29 04:54:22

问题


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


回答1:


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 (that cannot be used on Apple Store apps as well) 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


来源:https://stackoverflow.com/questions/59940847/ios13-alternative-to-voip-push-notifications-enterprise-to-silently-communica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!