- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 LaunchAgent,使用 HockeyApp 进行崩溃报告。现在我注意到 HockeyApp 没有报告未捕获的异常,就像在普通的 macOS 应用程序中一样。
例如:
- (void)upperCaseString:(NSString *)aString withReply:(void (^)(NSString *))reply {
NSArray *array = [NSArray array];
reply([array objectAtIndex:23]);
}
从未到达NSUncaughtExceptionHandler
,但控制台记录:
<NSXPCConnection: 0x7fe97dc0f110> connection from pid 44573: Warning: Exception caught during invocation of received message, dropping incoming message and invalidating the connection.
问题是如何获取 HockeyApp 报告的未处理异常。
最佳答案
XPC 似乎有自己的@try @catch block ,它捕获方法内未处理的异常,记录异常,然后调用-[NSXPCConnection InterruptionHandler]
。
此问题已通过 rdar://48543049 报告给 Apple .
注意:这些不是复制和过去的解决方案,请仔细评估您的崩溃报告框架。我链接到 PLCrashReporter 的实现细节。
@try @catch block :
- (void)upperCaseString:(NSString *)aString withReply:(void (^)(NSString *))reply {
@try {
NSArray *array = [NSArray array];
reply([array objectAtIndex:23]);
} @catch (NSException *exception) {
NSUncaughtExceptionHandler *handler = NSGetUncaughtExceptionHandler();
if (handler) {
handler(exception);
}
}
}
讨论
HockeyApp 使用 PLCrashReporter 进行崩溃报告。 PLCrashReporter 注册一个 NSUncaughtExceptionHandler
( code )。因此,上面的代码会将异常转发到 PLCrashReporter 异常处理程序并终止 ( code ) XPC。
Mattie建议再次@throw异常,以触发内部XPC@catch block 以及可能的内部清理和日志记录。 这是需要考虑的事情。特别是如果您在连接的 LaunchAgent/Server 端的 NSXPCConnection
上有一个自定义的 interruptionHandler
!
现在我不会再扔它了,因为我的 XPC 是完全无状态的,只要崩溃就应该没问题。
解决方案 A 的缺点是通过 XPC 公开的每个方法都需要这个@try @catch block 。
使用 NSProxy
捕获所有未处理的异常作为 NSXPCConnection exportObject
:
@interface LOUncaughtExceptionHandlerProxy : NSProxy {
NSObject *_object;
}
@end
@implementation LOUncaughtExceptionHandlerProxy
- (instancetype)initWithObject:(NSObject *)object
{
NSParameterAssert(object);
_object = object;
return self;
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
return [_object methodSignatureForSelector:selector];
}
- (void)forwardInvocation:(NSInvocation *)invocation
{
@try {
[invocation invokeWithTarget:_object];
} @catch (NSException *exception) {
NSUncaughtExceptionHandler *handler = NSGetUncaughtExceptionHandler();
if (handler) {
handler(exception);
}
}
}
@end
在 NSXPCListener
监听器中进行设置:
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
XPC *exportedObject = [XPC new];
LOUncaughtExceptionHandlerProxy *proxy = [[LOUncaughtExceptionHandlerProxy alloc] initWithObject:exportedObject];
newConnection.exportedObject = proxy;
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(XPCProtocol)];
[newConnection resume];
return YES;
}
解决方案 A 的所有详细信息均适用于解决方案 B。
在 macOS 上可以使用ExceptionHandling.framework,它的问题在 BITCrashExceptionApplication.h 中有很好的概述。 .
讨论
框架没有移植到 iOS 上绝不是一个好兆头。另请注意Matties评论:
I've had interactions with Apple that directly indicate that ExceptionHandling.framework is no longer supported. And, in my experience while working on Crashlytics, it had some fundamental interoperability issues beyond what is indicated in that quoted header.
关于objective-c - XPC 和异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54967355/
我正在尝试创建 XPC 服务,但似乎没有创建该服务。在我的服务的 main 方法中,我做的第一件事是对 syslog 进行一些调用,以便我可以查看服务是否开始运行。这些日志消息永远不会出现在日志中。
我正在开发一个应用程序,其中我从主应用程序中分离出了两个不同的 XPC 服务。我希望 XPC 服务与其他 XPC 服务进行通信,其他 XPC 服务将进行一些处理并将数据返回到第一个服务,第一个服务将进
我正在开发一个应用程序,其中我从主应用程序中分离出了两个不同的 XPC 服务。我希望 XPC 服务与其他 XPC 服务进行通信,其他 XPC 服务将进行一些处理并将数据返回到第一个服务,第一个服务将进
免责声明:我是 MacOS/Xcode 的新手 我想在 Swift 中构建一个简单的 XPC 启动代理(即:在 ~/Library/LaunchAgents 中)但我找不到太多文档。 我从 Xcode
在我的主应用程序包中,我包含了支持 XPC 服务。应用程序是沙盒的,一切都工作得很好,除了当我从 XPC 服务应用程序调用 [[NSUserDefaults standardUserDefault]
我按照 Apple 推荐的高风险操作实现了 XPC。问题是,当 XPC 崩溃时,它会向用户显示崩溃对话框。我知道这段代码有时会崩溃,这就是我首先实现 XPC 的原因。那么有什么办法可以抑制崩溃报告吗?
我正在尝试将 Wine 1.7.13 移植到现代 Cocoa 中。我正在考虑在 XPC 服务的进程中运行 Windows 二进制文件,以实现安全隔离和防崩溃。然而,有一个问题:据我所知,XPC 服务是
我正在使用 C 接口(interface)来实现 XPC 服务;顺便说一句,除了以下问题之外,我的 XPC 服务运行得非常好。 有一天我尝试通过 XPC 发送一个“大”数组; 200,000 个条目的
这不是一个与代码相关的问题,因为我在过去 2 小时内没有添加任何新代码,但我正在使用这个 cocoapod ( https://github.com/ealeksandrov/EAIntroView)
我正在尝试检测是否通过错误处理程序安装了辅助工具,但错误 block 不会被执行,成功 block 也不会执行。当 helper 已经安装时,它工作正常。它只是在有错误时不捕获错误。在文档中总是执行这
我有一段代码使用 NSURLsession 触发几个请求,有时我在 xcode 的调试器上收到以下消息 received XPC error Connection interrupted for me
是否可以在 XPC 服务中使用 AVFoundation 和 OpenCV?我有这么简单的代码 #include #import @interface AppDelegate(){ cv:
我在从 XPC 服务的 block 回调中传输 NSAttributtedString 时遇到了很大的问题。 我试图将基本字符串返回为: NSDictionary *arrayComa = @{NSF
我有一个 LaunchAgent,使用 HockeyApp 进行崩溃报告。现在我注意到 HockeyApp 没有报告未捕获的异常,就像在普通的 macOS 应用程序中一样。 例如: - (void)u
我的 cocoa 应用程序设计是一个 .app(UI)和三个 XPC 服务。 主应用程序需要文件只读才能显示powerbox并在 UI 中显示所选路径 com.apple.security.app-s
我有一个窗口应用程序,为了添加一些功能,我需要另一个应用程序,该应用程序在登录时启动并将数据同步到服务器(如果可用)。 我尝试过 NSDistributionNotification,但它在沙盒应用程
我成功创建了 XPC 服务并通过从主应用程序发送消息与 XPC 服务进行通信。但我想知道的是,是否可以发起从XPC服务到主应用程序的通信。 Apple documentation说XPC是双向的。如果
我最近升级到 Swift 5、Xcode 版本 10.2 (10E125),在修复了正在进行的应用程序上的一些编译问题后,看到了这个新的、以前从未见过的请求。通过直接搜索,我在我的项目中找不到任何证据
我的应用程序包含一个内核扩展作为关键组件。该内核扩展由系统控制套接字控制。出于安全原因,该系统控制套接字仅接受来自 super 用户的连接。 为了从我的常规非 super 用户应用程序进行通信,我有一
我正在尝试获得一个简单的命令行 Swift 应用程序,稍后将用于与 Chrome\Firefox 进行本地消息传递,以与工作场所的其他应用程序进行通信。 主 UI 应用程序(即 XPC 服务器): /
我是一名优秀的程序员,十分优秀!