I need to lauch iOS Simulator that uses specific language using command line. So I found that I can use
instruments -w <device>
and it is working great, I can set specific device. But how can I run simulator with specific language? I've tried adding
-AppleLanguages -AppleLocale
but there are some warnings:
Instruments Usage Error : Specified target process is invalid: -AppleLanguage
thanks!
The only way to launch iOS Simulator with specific language is to change contents of its .GlobalPreferences.plist file. Using xcrun tool will not work because it passess arguments to launched app and not changing language of simulator itself. Manipulation on .GlobalPreferences.plist is quite difficult because it is a binary plist file, so you cannot modify it as 'normal' xml. The easiest way to change its contents is to write simple Xcode Command Line Tool application, Foundation SDK has all tools needed to modify binary plists.
To run your app must be installed and located (if not, will open default language)
Use this command to run your app with some language
xcrun simctl launch <deviceid> <appid> -AppleLanguages "(pt-BR)"
Sample:
xcodebuild -sdk iphonesimulator8.4 -arch i386 install DSTROOT=SomeFolder
xcrun instruments -w "iPhone 6 (8.4 Simulator)"
xcrun simctl install booted SomeFolder/Applications/YourApp.app
xcrun simctl launch booted com.yourdomain.yourapp -AppleLanguages "(pt-BR)"
Have a look at:
https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/TestingYourInternationalApp/TestingYourInternationalApp.html
Search for "Testing Specific Languages and Regions"
Perhaps it could also be a solution creating different targets. Each target has configured another language
Related
I've recently started learning Swift and SwiftUI for iOS development and I completely understand how to run my apps for testing using XCode. You just click the play button with whatever simulator device is selected. However, I really don't like using XCode. I want to use VSCode for my development. Looking online I can find very complicated tutorials on how to build my project for release on the App store or "Ad-Hoc" from the terminal. But, I don't think this is what I need. I'm wondering if there is a way to build and run my app from the terminal on to a simulator or personal device (connected with USB)? I understand I can just have XCode open on the side and run it from there while developing from VSCode, but, my computer is kind of old and having both those apps open makes my fans go crazy.
You can follow this guide on how to build your project using xcodebuild.
Assuming you are in the directory with the .xcodeproj file, the command will look something like this:
xcodebuild -destination "platform=iOS Simulator,name=iPhone 14 Pro Max,OS=16.0" -scheme YourScheme SYMROOT="./build" build
Of course, you can choose any simulator you like. You can find a list of the simulators by doing xcrun simctl list.
The built app will be located in a folder called build/Debug-iphonesimulator, or build/Release-iphonesimulator, depending on your default configuration. The configuration can be set by the -configuration option.
Now you can launch the simulator. Here is a guide for that. Basically, you just specify the UUID of the simulator (again you can find this using xcrun simctl list), and then launch Simulator.app. Example:
xcrun simctl boot 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/
To install the built app, you also need the UUID (see also this answer)
xcrun simctl install 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1 build/Debug-iphonesimulator/YourApp.app
Finally, you launch your app by specifying the UUID of simulator, and the bundle ID of your app (source)
xcrun simctl launch 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1 com.mydomain.YourAppBundleId
We have the issue that with every new Xcode version all of our simulators are re-created in with system language German and system region Germany. But we need to work with a special "development language". In our case that is en_BZ.
Additionally when I try to set the language now wirth Xcode 14 the simulator crashes and the only solution to bring it back is to erase its data.
How can I change system language/region permanently so I don't have to set that tediously with every new Xcode version and for every simulator device?
This is actually possible suing the tool simctl. Using the following set of commands this can be fully automated:
xcrun simctl list -j "devices" | jq -r '.devices | map(.[])[].udid' | parallel 'xcrun simctl boot {}; xcrun simctl spawn {} defaults write "Apple Global Domain" AppleLanguages -array en; xcrun simctl spawn {} defaults write "Apple Global Domain" AppleLocale -string en_BZ; xcrun simctl shutdown {}'
Explanation
The {} is a placeholder provided by parallel and it represents the respective udid obtained in the first steps above. This is what the single commands do, one by one:
xcrun simctl list -j "devices": Lists all devices that are also available in Xcode in JSON format.
jq -r '.devices | map(.[])[].udid': Filters the udid of each device from the JSON output. It uses the tool jq which is a super powerful JSON parser. You have to install that using brew install jq.
parallel [...]: This launches the following set of command instructions in parallel. This is super useful since the first one, booting all simulators takes a lot of time. Doing this one by one would take forever. Please brew install parallel first.
xcrun simctl boot {}: Boots each simulator.
xcrun simctl spawn {} defaults write "Apple Global Domain" AppleLanguages -array en: Sets English as one pf the preferred languages.
xcrun simctl spawn {} defaults write "Apple Global Domain" AppleLocale -string en_BZ: Sets English as used system language and Belize as system region.
xcrun simctl shutdown {}: Shutdown each simulator again.
I'm trying to figure how to build metal shaders for iphone os using xcrun.
I have (the almost latest) Xcode 11.3.1 installed on macos 1.4 Mojave.
xcrun --sdk iphoneos --show-sdk-path
reports that the sdk cannot be found.
I checked
xcrun --sdk macosx --show-sdk-path,
which reports
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk
The iphone and TVOS sdks don't seem to be there at all. However, I'm able to use the Xcode IDE to build to an iphone. I checked the build logs and found that one step sets the SDKROOT to:
SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk which is inside the Xcode bundle.
I want to be able to build from the command line, but clearly the correct path hasn't been registered. Do I need to reinstall the command line tools, or is there some setting I need to add an SDK to xcrun?
How do I proceed?
I very quickly realized that I must have been using the bare-minimum command line tools from when I first installed the machine.
In Xcode, go to Preferences>Locations and select a specific set of command line tools from the drop-down. This updates xcrun to point to the full collection of SDKs that Xcode provides.
http://cl.ly/image/2K1H000s170l
Please refer to my screenshot. That's a manual way to set default device in iOS simulator. Can anyone tell me how to do that from command line? Many thanks!
I need that as part of my Jenkins project setup. Thanks a lot!
You can use xcrun to open your device
xcrun instruments -w "iPhone 6 (8.4 Simulator)"
If you want to know all devices installed
xcrun instruments -s
If you need to build and install some app use.
xcodebuild -sdk iphonesimulator8.4 -arch i386 install DSTROOT=~/YourApp
xcrun simctl install booted ~/YourApp/Applications/YourApp.app
You can choose the device that is booted when the simulator launches by passing it on the command line. See Xcode 6 - Launch simulator from command line
Yes as mentioned this is a duplicate.
But to answer your question,
You can use the instruments to launch the simulator of your choice. For Ex:
xcrun instruments -w "iPhone 6 (8.2 Simulator)"
"From the screen shot it seems like you are already on iOS 8. "
I have a .app file shared from a developer which i would like to run in iOS 8 simulator. I have seen similar questions which has solutions for older versions of iOS which is no longer working for iOS 8. Can someone point out what needs to be done to run the .app file in an iOS 8 simulator without using xcode.
Boot the simulator you want to install it to in the iOS Simulator and then do the following:
xcrun simctl install booted /path/to/Your.app
xcrun simctl launch booted com.yourcompany.yourapp
The "booted" token was not supported on older versions of simctl in Xcode 6.0. If you get an error, please use the full device UDID instead of "booted". You can determine the UDID by running xcrun simctl list
If the application crashes after installing in the simulator using the command,
xcrun simctl install booted /path/to/Your.app
It's probably because the architecture issues, since we used the device build instead of simulator build.
The basic architecture difference between the iphone simulator and iphone device is
iPhone simulator uses the architecture i386 or x86_x64
whereas,
iPhone device uses the architecture arm64 or armv7 or armv7s
We can find each device architectures in this link. So to over come this problem we need to get the simulator build by changing the xcode build location settings.
SOLUTION :
To change the build location settings, Open your xcode and follow the below steps.
Go to xcode preferences.
Choose the locations tab.
In the 'Derived Data:' section click 'advanced', from the resulting screen choose 'legacy'.
Now build the application, after successful build go to 'Your-App-Folder/build/Debug-iphonesimulator' in finder, and copy the build available on the same folder with the extension .app
Copy that and run the above command answered by #jeremy.
xcrun simctl install booted /path/to/Your.app
After running this command, note that your simulator is installed with the build you specified. There you go, run the application in simulator by clicking the corresponding app and use it.
I deliberately write this solution to help the needy, those who are clueless about the architecture issues specified above.
Happy Coding :)
iOS Simulator also supports dragging and dropping for installing .app files
Open Simulator
you can do it through XCode under XCode > Open Developer Tool > Simulator
to open it "without using xcode", see these answers.
Find the .app file in Finder and drag it into your Simulator window
Wait for the app to install and launch it
For developers looking to provide a simulator build to theirs testers, these are the steps that I followed to create and test a build -
Add i386 in valid architectures section of build settings.
Open terminal and navigate to your project folder. Then execute the command -
xcodebuild -arch i386 -sdk iphonesimulator8.1
(This will build the application)
To install the application on simulator, run the command mentioned in the above answer i.e -
xcrun simctl install booted /path/to/Your.app
Now you should be able to run the app by clicking on the installed application in the simulator.
I have followed all the above commands and stuff but none worked. All I was doing is creating .app through archiving the app from Product->Archive and then converting that generated .ipa to .app by changing the extension to .zip.
But the app is crashing as and when it is being launched.
For those facing the same issue, go to
DerivedData/projectname/Build/Products/Debug-iphonesimulator/
folder. There you can find the .app file with app name. You need to use this .app file by dragging and dropping onto the simulator. Product->Archive->.app doesn't work.