App crash "Library not loaded:" iOS 9 Framework on iOS 8 device

I want my app to support iOS 8 and 9. I updated my app to use Swift 2 and added spotlight indexing for iOS 9 devices, but now on iOS 8 my app will crash on launch with the error


dyld: Library not loaded: /System/Library/Frameworks/CoreSpotlight.framework/CoreSpotlight
  Referenced from: /private/var/mobile/Containers/Bundle/Application/77AE43CF-C71D-462B-92FD-D8EAF6DB53B5/TVShows.app/TVShows
  Reason: image not found


If I comment out the code I have in the app delegate method

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool

then the app will run fine.

Here is my implementation of continueUserActivity,

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
       
        if #available(iOS 9.0, *) {
            if userActivity.activityType == CSSearchableItemActionType {
                if let showIdentifier = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String {
                    // More code
                }
            }
        }
        else if let userInfo = userActivity.userInfo {
            /
            if let episodeTraktID = userInfo["displayEpisode"] as? NSNumber {
                // More code
            }
        }
       
        return true
    }


If I comment out from the first if to the else, then it will work fine. Is this just a bug or how can I implement CoreSpotlight and keep this method for handoff on iOS 8?

Hey,


I would recommend checking the CoreSpotlight framework is marked as Optional and not Required in your project settings.


You can do this by

  1. Opening on your Xcode Project in the project navigator.
  2. Select your target and navigate to the Build Phases tab.
  3. Expand the "Link Binary With Libraries" section.
  4. Make sure the status of the CoreSpotlight framework is set to Optional.


This will ensure the framework is not forcefully loaded into memory, causing a crash on older versions of iOS.


- Tom

I did that, the app still crashes unfortunately.


EDIT:

Here is sample code demonstrating the crash, I also filed a radar (21986662)

https://dl.dropboxusercontent.com/u/29315938/CoreSpotlightLinkingCrash.zip

I was running into the same problem. Adding CoreSpotlight to "Linked Frameworks", marking it as Optional, and then running Clean Build Folder (Alt+Shift+Command+K) fixed the issue for me (Xcode7 Beta4).

Still crashes for me. I have to comment out code from

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool

To get it not to crash, but the code is not called which is why its strange that it fixes the issue 😟 I hope this is fixed in the next beta

App crash "Library not loaded:" iOS 9 Framework on iOS 8 device
 
 
Q