Executing shell commands for iOS apps - ios

How do I execute shell commands for iOS app in Xcode(it does not support NSTask.h as the app is sandboxed)?

You can't. There is no (public) shell available, and also no (public) high-level API to run external commands. This is a deliberate restriction of iOS.
You might be able to use low-level POSIX/Mach APIs like posix_spawn to start an executable that you bundle, though. But even if you manage to do that, it's likely that Apple will reject your App Store submission if you do that.

Related

Run any app in iOS 10+ from command line without jailbreaking

Is there a way to run any app in iOS 10+ from command line/Mac without jailbreaking?
Re-signing and none of the existing tools seem to work (ios-deploy, Instruments) nor have I been able to find a way via iTunes or other programs.
Yes it is possible for any App you have the source code for.
No it is not possible for any App you acquired from the App store or direct download.
Not quite sure I fully understand your emphasis on any app, but here is what I understand:
1) If you mean you want to run any app from the app store that can currently be downloaded, and you have a .ipa file, you can definitely install it manually to another device using this method (iTunes drag and drop)
2) If, however, you're trying to run an .ipa on a Simulator, that's not possible, as described by this answer.
3) Lastly, if you have source, which I'm confused about since you mention re-signing, then you can easily build that source into an executable for either Simulator or device using either Xcode, or since you asked about command line, you could also use xcodebuild, info found here
I hope one of these 3 options is what you're looking for, as it's hard to tell from the wording of the question. If it's not, expanding on exactly what use case you're trying to resolve would be very helpful.
From the comments in #BHendricks answer, it seems you want to use the command line on your computer to start apps that are installed on an iOS 10+ device.
This is not possible without jailbreaking the phone!
On a jailbroken phone it might be possible to write something that connects over ssh and starts apps, but on vanilla iOS this is disabled for security. You could search for an app that you can send commands, but I highly doubt iOS apps have access to system features like starting other apps, as this is also a large security risk.
If you have the ipa, you can install the app via iTunes. This is what we used to ask QAs to test apps on devices and it works fine. Please refer to this [SO] for detail Install IPA with iTunes 12.
Use Cydia Impactor (cydiaimpactor.com) to sign the app. 99% chance it will work

How to run an executable in iOS App?

I want to run an executable file in my iOS app. (or execute some command line commands)
I think this can be done with the help of NSTask, but that doesn't seem to be available in iOS (its available for mac OS X only).
So,
How can i run an executable from my app ? OR How can i execute shell commands from my app ?
How can i make use of NSTask in iOS ?
Are there any other libraries like NSTask which i can make use of ?
If none of the above is possible, please let me know a way around.
I want my app to be uploaded on the app store, so please don't answer anything related to jailbreaking.
Also,
Don't tell me apple would reject it, i want to take a chance.
You can't run an executable from your app due to the sandboxing. From the list 1-4 are not possible.
NSTask is not available because it would violate the sandboxing.

Update cordova app without app store

i need to update an cordova app via my own api. Is there any solution available?
I am thinking about a process like some games have - like "Clash of Clans" on start.
I've just thought about using file-api, but it seems like the directory is absolutely write-only and there is no way to execute my app from another place.
Sadly i can't use an simple app store update, as there is no internet connection on the devices. They just connect to an terminal provided with my software, in a closed environment.
So every third-party services are out :(
My thoughts is that i ship an app-update within my terminal software and the devices get that information an update themselves.
Any ideas?

iOS : Shell script from an iOS App

I believe, we can run shell scripts from iOS App.
Can someone tell me what is the default shell in iOS and how to call a shell script from iOS App?
((
Please consider that I run the script in background. I catch the return value of the script into a variable. (following line is not exact code. Pseudo. Zsh shell is default - I think.)
myVar=MyiOSAppBundle\Script.zsh
))
Regards
You cannot do this in iOS. If you are jailbroken, you may be able to, but otherwise applications are not given admin permissions.
Apple's guide on The iOS Environment in which an app lives may give you more insight.
Apple says in their May 2012 document titled "iOS Security":
Because iOS achieves a reduced attack surface by limiting listening ports and removing unnecessary network utilities such as telnet, shells, or a web server, it doesn’t need firewall software.
Your question lacks details. What are you trying to accomplish? What have you tried? Are you intending to develop for a jailbroken device or for the App Store? Please edit your original question or create a new, more complete one.

Xcode - How to move app out of sandbox with run script?

Basically from what I understand is that if my app wants to use serial communication via the dock connector (pins 12 / 13) the app has to live outside the app sandbox folder. Now I don't want to have to ssh into my phone and copy theAppFolder.app to /Applications/ everytime I click Run in Xcode (that would just be silly).
Now while doing some research I came across this blog post. Down in the comments, someone gives the idea of what I am talking about in this question.
Now is his solution the best way to do what I am thinking of doing, or is there a more elegant solution?
A bit late, but I use Xcode's build command with a post-build script to get my app on my jailbroken iOS device and also start it using a tool from Cydia (it will actually run the app from the /Applications directory). Check out my answer here for more info. The thing still missing is the ability to debug, but I've gotten used to using NSLog and tailing the syslog.

Resources