ios - 重新定义外部 block (promiseKit)

标签 ios objective-c promisekit

我正在使用 PromiseKit(很棒的框架,顺便说一句!)来处理我的应用程序和服务器 API 之间的通信。我想创建某种全局处理程序来响应诸如通知用户我的许多 promise 中的任何一个缺乏网络连接之类的事情。

PMKPromise.h 文件列出了一个未处理的错误处理程序:

/**
Called by PromiseKit in the event of unhandled errors.
The default handler NSLogs the error. Note, your handler is executed
from an undefined queue, unless you manage thread-safe data, dispatch to
a safe queue before doing anything else in your handler.
*/
extern void (^PMKUnhandledErrorHandler)(NSError *);

此类型然后在 PMKPromise.m 文件中实现,尽管文档 block 暗示这可以被覆盖。我的问题是我该如何重新定义这个变量?

复制 .m 文件中使用的相同语法会给我一个链接器错误

void(^PMKUnhandledErrorHandler)(id) = ^(NSError *error){
    //...
};

==> duplicate symbol _PMKUnhandledErrorHandler

最佳答案

PMKUnhandledErrorHandler = ^(id error) {
    // your code here
};

警惕不方便的错误处理程序,有时它会在错误发生后的很长一段时间内被调用,具体取决于相关 promise 何时被解除分配。它是可靠的,但并不总是立即可靠。

99% 的时间它会很慢,因为某些对象仍然在您的链中某处处理 promise ,并且它很快将被释放但尚未释放。

关于ios - 重新定义外部 block (promiseKit),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29655202/

相关文章:

ios - 为什么我总是从 Firebase 中删除数据?

ios - 移动平台? Cocos2d 和 Tiled

iphone - 控制 iPhone 上的自动更正 View 位置

swift - PromiseKit 捕获多个参数

ios - Swift : 'case .success(let dict):' 是什么意思

ios - GMSPlacePickerViewController 始终返回错误 - 您的 API key 上配置了按 IP 或按引用者限制

ios - 如何解决钥匙串(keychain)错误 : Implicit conversion of C pointer type 'CFTypeRef'

php - NSURLSessionUploadTask 没有将文件传递给 php 脚本

iphone - UIBarButtonItem中的按钮框架

ios - PromiseKit 和 CloudKit 保存(使用 Swift)