0

Basically I have a view controller that acts as a setting page. On of the cells calls the "killall backboardd" function to restart the springboard.

However since rewriting my app from objective-c to use swift, I found I have ran into some errors.

The first being that system() command is deprecated. Ok. So it suggest to use posix_spawn API instead. Ok, don't know anything about that, haven't really had a need to research. So I decided to just use NSTask. I use it in the old version a lot so why not this one?

I added the runtime header to the Foundation.framework folder. cleaned project, restarted xcode only to find that I have the warning. "Use of unresolved identifier 'NSTask'

I have the import Foundation so whats with the error? Here is what I'm working with:

        let task = NSTask() <----ERROR
        task.launchPath = "/usr/bin"
        task.arguments = ["killall backboardd"]

        let pipe = NSPipe()
        task.standardOutput = pipe
        task.launch()

        let data = pipe.fileHandleForReading.readDataToEndOfFile()
        if let output = NSString(data: data, encoding: NSUTF8StringEncoding) {
            print(output)
        }

        task.waitUntilExit()
        let status = task.terminationStatus
        print(status)

It just seems like the file isnt even linking up how it did in the past. Any help would be greatly appreciated.

ChrisOSX
  • 724
  • 2
  • 11
  • 28

1 Answers1

0

afaik. NSTask doesn't exist in iOS SDK. Maybe try objc_getClass("NSTask"); to bypass the compile check.

Zhang HanSheng
  • 342
  • 1
  • 13
  • 1
    Natively it does not, you are correct on that, however I am developing on a jailbroken device. So using NSTask as a private header is ok with me as I have no need to submit to Apple. This has taken a backseat though until Apple can figure out how to compile the app without tripling the size of my app with the swift library. – ChrisOSX Dec 11 '15 at 09:38
  • @ChrisOSX that's why I advice simply go runtime to avoid all these overhead – Zhang HanSheng Dec 11 '15 at 09:39
  • @ChrisOSX How did this end up getting solved? `let task = objc_getClass("NSTask")`? – kuilin May 22 '17 at 02:48
  • It never ended up getting solved as I ditched swift and stuck with objective-c. To my previous comment, the swift library makes my app a ridiculous size for what it is. – ChrisOSX May 22 '17 at 08:38