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

后端 未结 1 476
走了就别回头了
走了就别回头了 2021-02-11 03:42

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 purpos

相关标签:
1条回答
  • 2021-02-11 04:41

    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
    
    0 讨论(0)
提交回复
热议问题