本文介绍了iOS13:替代 VOIP 推送通知(企业)以在后台与应用程序进行静默通信,因为 iOS13 已将其杀死的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在我们的企业环境中大约 4 年时间里,我们很高兴地使用 VOIP 推送通知来远程访问用户的平板电脑,以进行维护和远程数据修复.与常规 APNS 不同,VOIP 推送通知即使未运行也会访问该应用程序.我应该认为苹果会在某个时候杀死它.

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.

是否有人知道可以绕过 pushkit 要求调用 reportNewIncomingCallWithUUID 的私有 API,这会带来全屏调用 UI,或我无法想到的其他机制来访问应用程序中的应用程序背景即使被杀死 - 通知服务扩展 也不会工作(我相信),因为它只适用于屏幕消息.谢谢

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

推荐答案

如果你不打算发布到 Apple Store 上,并且不关心私有 API 的使用(可以随时更改,破坏你的代码)),你可以使用method swizzling来改变系统调用的函数的实现,使应用程序崩溃.

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.

就我而言,我有一个具有 swift 和 objc 互操作性的项目.我是这样做的:

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

其他选项(也不能在 Apple Store 应用程序上使用)是使用 Xcode 10 构建它,或者使用 iOS SDK 12 的副本从 Xcode 11 手动覆盖 iOS SDK 13.

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

这篇关于iOS13:替代 VOIP 推送通知(企业)以在后台与应用程序进行静默通信,因为 iOS13 已将其杀死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 04:44