使用UNUserNotificationCenter时,bundleProxy!= nil导致iOS 11崩溃 [英] iOS 11 crashing with bundleProxy != nil error on using UNUserNotificationCenter

查看:104
本文介绍了使用UNUserNotificationCenter时,bundleProxy!= nil导致iOS 11崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码行是我们的应用突然在某些用户上的iOS 11/11.0.1/11.0.2/11.1.1/11.2.2崩溃的地方:

The following line of code is where our app has suddenly started to crash on iOS 11 / 11.0.1 / 11.0.2 / 11.1.1 / 11.2.2 for some users:

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

我们已经在didFinishLaunchingWithOptions中找到了它.崩溃报告说:

We've got this in didFinishLaunchingWithOptions. The crash report says:

Fatal Exception: NSInternalInconsistencyException
Invalid parameter not satisfying: bundleProxy != nil

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x1869b3d38 __exceptionPreprocess
1  libobjc.A.dylib                0x185ec8528 objc_exception_throw
2  CoreFoundation                 0x1869b3c0c +[NSException raise:format:]
3  Foundation                     0x187342c24 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4  UserNotifications              0x18fcc973c -[UNUserNotificationCenter initWithBundleProxy:]
5  UserNotifications              0x18fcc950c __53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke
6  libdispatch.dylib              0x186339048 _dispatch_client_callout
7  libdispatch.dylib              0x18633c710 dispatch_once_f$VARIANT$mp
8  UserNotifications              0x18fcc94ac +[UNUserNotificationCenter currentNotificationCenter]

它显然来自iOS.还有其他人遇到相同的错误吗?知道发生了什么事吗?

It's coming from iOS clearly. Any one else experiencing the same error? Any idea what's going on?

推荐答案

我不确定这是否对每个人都有效,但是我已经为我的用例弄清楚了.我创建了一个iOS应用程序使用的框架.该框架使用UNUserNotificationCenter设置警报.似乎由于某种原因,当从框架内部使用此代码时,捆绑"未正确初始化.有时它起作用,有时却不起作用.顺带一提,此bundleProxy是通知框架所依赖的某种代理.由于代码是从框架内部执行的,因此可能在运行时找不到此捆绑包,并且系统返回nil.尝试从捆绑位置不正确的Framework加载资源时,通常会遇到这个问题.

I'm not sure if this is going to work for everyone, however I've figured it out for my use case. I had created a framework that the iOS app used. This framework was using UNUserNotificationCenter to setup alerts. It seems for some reason, the 'bundle' does not get correctly initialised when this code is used from inside a framework. Sometimes it works, sometimes it doesn't. This bundleProxy, by the sound of things, is some kind of a proxy that the notification framework relies on. Since the code is executing from inside of a framework, perhaps this bundle is not found at runtime and the system returns nil. I've had this issue in general when trying to load resources from the Framework where the bundle location isn't correct.

无论如何,对我来说,解决方案是在启动时在应用程序的委托中存储对[UNUserNotificationCenter currentNotificationCenter]的引用,然后将其传递给任何想要使用它的方法.在应用程序完成启动时,如果调用代码是应用程序本身的二进制文件,则此proxy似乎已正确加载.这似乎已经为我解决了.

Any way, the solution for me was to store a reference to [UNUserNotificationCenter currentNotificationCenter] in the app's delegate at launch, and then pass this to any method that wanted to use it. By the time the app has finished launching, this proxy seems to load correctly if the calling code is the app's binary itself. This seems to have fixed it for me.

这篇关于使用UNUserNotificationCenter时,bundleProxy!= nil导致iOS 11崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆