I've added MobileCoreServices.framework to my Xcode project, and have the statement import MobileCoreServices
in top of my file.
I have the line of code
let test = LSApplicationWorkspace.defaultWorkSpace()
And xcode said Unresolved Identifier LSApplicationWorkspace
I tried cleaning and rebuilding the project. Any ideas?
Point 1: LSApplicationWorkspace is private api, so if you use this and will upload your app to app store, it will get rejected.
Point 2: If you are having any in-house app and still want to use this in your app, then below is the way to use it.
MobileCoreServices
Framework in your bundleLSApplicationWorkspace.h
file with the code exactly same as the code provided at here "https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MobileCoreServices.framework/LSApplicationWorkspace.h".LSApplicationWorkspace.h
file into your bundle#import "LSApplicationWorkspace.h"
in your bridging headerimport MobileCoreServices
in your current file and add your code let test = LSApplicationWorkspace.defaultWorkSpace()
, it will work fine.NOTE: For using any private header, you must have to include its .h
file into your code. You can find any private headers by searching "runtime headers" in google. You will get all runtime headers. And to include that header in your swift code, you need to go via bridging-header.
The Swift compiler is telling you it has not idea about a class called LSApplicationWorkspace. This is because it is a private class not described in any headers available to you as a 3rd party developer. Should you be caught using LSApplicationWorkspace APIs during App Store review, your submission will be rejected. Given this class contains APIs that change between OS versions (by virtue of being undocumented and private), and APIs which are for good privacy reasons not available to 3rd party devs, using it is almost certainly a really bad idea, even if you are technically able to do so with either of the the following methods.
Create a private module map file where you import a header you somehow acquired for the private framework that contains LSApplicationWorkspace. This way of calling to LSApplicationWorkspace (or indeed any method involving using the headers for Mobile CoreServices – i.e. any method except for performSelector mentioned below) would almost certainly get your app submission booted from App Store review, because this method of (ultimately) Objective-C method calls would be visible to static analysis methods Apple runs on your code as part of App Store review.
Use NSClassFromString:
let LSApplicationWorkspace_class:AnyObject = NSClassFromString("LSApplicationWorkspace")! as AnyObject
let workspace = LSApplicationWorkspace_class.perform(NSSelectorFromString("defaultWorkspace"))! as AnyObject
With the above code you now get an instance of LSApplicationWorkspace with which you can perform code with performSelector – should you know what selectors it responds to (… in the particular operating system version you are running on). Again though, doing anything with LSApplicationWorkspace is probably a bad idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With