温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - iOS13: Alternative to VOIP push notifications (enterprise) to silently communicate with an app in ba
apple-push-notifications background voip ios13 enterprise

其他 - iOS13:VOIP推送通知(企业)的替代品,可与BA中的应用程序进行静默通信

发布于 2020-04-08 17:34:52

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

有没有人知道的私有API的绕过pushkit要求调用reportNewIncomingCallWithUUID 这带来全屏来电UI,或者另一种机制,我想不出来访问后台应用程序,即使被杀- 通知服务的扩展赢得”之所以起作用(我相信)是因为它仅适用于屏幕消息。谢谢

查看更多

提问者
Nostradamus
被浏览
294
pepsy 2020-02-01 01:50

如果您不打算将其发布到Apple Store,并且不关心私有API的使用(私有API随时可能更改,会破坏您的代码),则可以使用swizzling方法更改由调用的函数的实现系统崩溃的应用程序。

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

  • 创建一个以PKPushRegistry+PKPushFix_m.h要点内容命名的文件
  • 将其包括在快速桥接标题中。

其他选项包括使用Xcode 10构建它,或从具有iOS SDK 12副本的Xcode 11中手动覆盖iOS SDK 13。


以下是要点的内容,以防将来无法使用:

#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