简体   繁体   中英

NSTask and iOS Swift 2.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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM