Xcode sometimes removes linked library

2019-02-22 16:08发布

When using different Frameworks in Xcode, the compiler and linker sometimes do not include that Framework in the library. The result is an immediate crash during the startup with the following message:

dyld: Library not loaded: /System/Library/Frameworks/UserNotifications.framework/UserNotifications
  Referenced from: /var/containers/Bundle/Application/1D41BD68-9B88-4D5D-B7AB-0D1C31979964/App.app/App
  Reason: image not found

I found one way to avoid this. Its just mentioning the parts of that library within the apps code directly like this:

UNNotificationRequest *unr = [UNNotificationRequest alloc];

Just including a file from that framework with #include <UserNotifications/UserNotifications.h> does not fix it. Nor does @import UserNotifications;

I have seen it with different libraries on different xcode versions for different ios versions.

Here are two other issues that have a more specific use case:

1) CABTMidiCentralViewController used in Storyboard only working if using code reference

2) Switching to Xcode 10 causes `UserNotifications.framekwor dyld: Library not loaded crash` for iOS9

Does anybody know why this is happening? And how to avoid that dumb part of code but still link / embed the desired framework?

P.S.

  1. I have set Always Embed Swift Standard Libraries to YES
  2. I have set Link Frameworks Automatically to YES

Update #1

The issue with the UserNotifications framework:

iOS9 & XCode 9 - WORKS

No crash on iOS9 with XCode9

iOS9 with XCode 10 - CRASH

Crash on iOS9 with XCode10

Using the simulator:

iOS9 & XCode 10 Crashh - simulator

Using a real device:

enter image description here

Update #2

It is not crashing when I change the framework from Required to Optional but then the push notifications are not working.

1条回答
戒情不戒烟
2楼-- · 2019-02-22 16:34

UserNotifications.framework is a system framework, and to be used it must exist on the system your application is running on. It was added relatively recently, so my guess is you're seeing the error about it being missing when running on older iOS versions that predate the framework's existence.

查看更多
登录 后发表回答