0

I am currently working on a package manager. I currently am trying to find a way to call in apt within an app in Swift.

The main issue is that Command Line cannot be called; I use StoryBoards to build the app, and thus do not have access to some properties given if written manually.

As I am working on it in a way it will not break in iOS 13, I use the latest Xcode; and thus the latest version of Swift.

I have tried NSTask; this can never be found; not in a class, not in a new object, not on his own, not in AppDelegate.

I have tried Process(); this doesnt seem to exist in this version

I have tried posix_spawn. This gave me hope because I could build it, but it did nothing. I tried to Log the output, and it returned empty.

Could the issue be that the Application needs additional permissions, and if so, in what way can I gain these permissions?

  • 2
    Did you `import Foundation` for `Process`? – Alexander Sep 17 '19 at 15:35
  • Yes, I did import Foundation for it. This has had no effect on the error message. It still does not work. I have looked into the Documentation within Xcode itself, and it seemed to be absent. – John NemECis Sep 18 '19 at 12:32

1 Answers1

1

For posix_spawn & NSTask to work you need to bypass the app sandbox restrictions. The apps that actually perform the jailbreak run a kernel exploit to achieve that, but that's not really practical.

That leaves you with installing your app in /Applications on the device. That's how package manager app for jailbroken devices like Cydia works.

Regarding NSTask you can either use the approach from here or some obj-c runtime gimmicks

let task = (NSClassFromString("NSTask") as! NSObject.Type).init()

var taskURL = //url to your file

task.setValue(taskURL, forKeyPath: "executableURL")

let selector = NSSelectorFromString("launchAndReturnError:")
let methodIMP : IMP! = task.method(for: selector)

var result: Bool = true
var error: NSError = NSError()
withUnsafePointer(to: &error) {
    result = unsafeBitCast(methodIMP,to:(@convention(c)(Any?,Selector,OpaquePointer)->Bool).self)(task,selector,OpaquePointer($0))
}

Process is MacOS only Swift API, I'm not aware of an easy way of accessing it in iOS.

Kamil.S
  • 5,205
  • 2
  • 22
  • 51