Context: Xcode Version 11.0 beta 2/Swift 5
I want to create a bundle to access on a physical iOS device. I tried all the solutions on How to make an iOS asset bundle?, but to no avail.
I have created a bundle in finder containing the file and subsequently moved to Xcode such that my directory structure looks like this:
*Project Name*
*Project Name*Tests
Products
somebundle.bundle
somefile.csv
I keep getting the error
the file "somefile.csv" couldn't be opened because there is no such file
when testing.
I am accessing the file through let text = try String(contentsOfFile: Bundle.main.resourcePath! + "/somebundle.bundle/somefile.csv")
But actually, printing the contents of Bundle.main.resourcePath (FileManager.default.contentsOfDirectory(atPath: Bundle.main.resourcePath!)) shows that the bundle is not located in Bundle.main.resourcePath, as this is the output:
["_CodeSignature", "PlugIns", "Base.lproj", "*Project Name*", "Frameworks", "Info.plist", "PkgInfo"]
So, how do I get the bundle into Bundle.main.resourcePath, as the answers to the question at the top seem to suggest should be the case?
To access the contents of a Bundle when the app is installed on a physical device you need to ensure that it is copied across during the build.
Go to your Project Settings -> Build Phases -> Copy Bundle resources and make sure that your bundle is listed there.
You will only be able to read the contents from there unless you copy it to the documents folder first before trying to edit/save.
Related
I am using XCode 9.2 and I want "upload" a data - lets say a database - onto my simulator so that when I run the XCode proejct, the data is already on the device. How would I upload a data onto the simulator and how to I get the path to access it in the app?
Is it done through XCode or the Finder? I know that I can access all the simulators here ~/Library/Developer/CoreSimulator/Devices but how do I know which simulator is i.e. the iPad? How do I get the path to the data? And does it matter in which folder I put the data?
You can do this without messing around in the Finder by simply adding the files you want to your Xcode project and making sure they are included in the "copy bundle resources" build phase. Those files will then be available to your app at runtime from within the main bundle, and you can access them like this:
if let url = Bundle.main.url(forResource: "yourfile", withExtension: "ext") {
let data = try Data(contentsOf: url)
// process the data here
}
If you need read/write access to the files, you need to copy them from the bundle to the app's sandbox directories, e.g. to your "application support" directory.
How do I install the XCUITest runner app and ipa on a real device and get the results?
I have a runner.app that was generated by building it for testing, and a deployed/signed .ipa.
Now what I would like to happen is to have it installed on a real device, execute it, and get the device log.
You can use bundleId :
let app = XCUIApplication(bundleIdentifier: "yourapp.bundle.id")
You can try to use:
xcodebuild test-without-building -xctestrun somepath/YourAppName_iphoneos14.4-arm64.xctestrun -destination 'platform=iOS, id=some_id'
I moved YourAppName_iphoneos14.4-arm64.xctestrun, YourAppName.app,
YourAppNameUITests-Runner.app to some local folder from a regular Library/Developer/etc.. build folder. Then I opened *.xctestrun file, which is an xml file, and modified paths to my local folder manually.
I couldn't find any official information about it but it seems like the *.xctestrun file is used by xcodebuild in order to find all relevant artefacts i.e both app folders. I would guess that's how they manage to run tests just with app's or ipa's without source code on various clouds...
PS. The question was about IPA, but it's convertible to the app, right? At least there is a thread - How to convert .ipa to .app file?
Edited with answer...
It is possible to achieve this. In order to build an ipa of the UI Testing app bundle you can follow these steps:
Open your project containing in Xcode.
Select the device you'd like to build the ipa for next to the scheme. This can be an actual device or a simulator.
Product > Build For > Testing
Find [your_ui_test_bundle_name].app file in Derived Data.
Derived data by default is located at ~/Library/Developer/Xcode/DerivedData/
To locate this file, dive into DerivedData for your project, navigating to Build > Products and then the respective directory based on what you chose in step 2. If you chose a simulator, look in -iphonesimulator/ or if you chose a device look in -iphoneos/. The UI test bundle .app file should be in that directory.
Create a directory named Payload case sensitive and it must be named this.
Move the .app file into the Payload directory.
Compress the Payload directory.
Rename the compressed directory to have a file extension of .ipa. You'll be prompted and select Keep .ipa.
Now you have you UI test bundle application saved as an ipa. You can also upload this ipa to a device manually in Xcode via the following process (bonus info, yay!)
Window > Devices and Simulators
Select your connected device.
Tap the + button under Installed Apps.
Navigate to and select your UI test .ipa file that you compressed previously.
It should install onto the device.
Credit where it is due: https://medium.com/ios-os-x-development/how-to-run-your-iphone-test-on-aws-device-farm-98f18086811e
Because of this unsolved problem I have to assemble my Qt Creator projects to Xcode projects and run it there. So, I need to setup icon for iOS app version. I tried two ways:
1.
I can add icons and Info.plist inside ready Xcode project. It works pretty well, but I have no desire to do that every time I assemble Qt project to Xcode project.
2.
Thus, I tried to add icons and plist to pro-file:
ios {
ios_icon.files = $$files($$PWD/ios/AppIcon*.png)
QMAKE_BUNDLE_DATA += ios_icon
QMAKE_INFO_PLIST = ios/Info.plist
}
This way I get incorrect Xcode project. There is no Info.plist in the files of project tree, however I have references to that file (in the folder of Qt project, it's not copied) in Target -> Build Settings -> Packaging -> Info.plist file. App icons of different size are presented in Xcode project, but they are references, not copies. When trying to run, I get:
Installation failed. Invalid argument.
After coping icons and plist to that project, it runs well, but application title is ${PRODUCT_NAME}.
I also tried to setup copying of Info.plist in pro-file these ways, but got the same results.
Does anybody know what is going on here??
Open the Xcode bulid file and go to build Settings>product bundle identifier . Now set any bundle id in the field . Now run the project , it will automatically create info.plist file and other set up like standard .
I had a sqlite file which was working fine on the simulator and the device.
Under my app folder on the mac, I can also see the file - coredata.sqlite.
I created a new coredata.sqlite. After this, I had to copy it over to the paths which were different for different targets (iphone 5 vs 6 vs 6+) and looked along the lines of :
.../Library/Developer/CoreSimulator/Devices/26292D7B-5001-497E-B23B-99455953F5F4/data/Containers/Data/Application/64849BCC-B86B-45DE-818F-3E67346C4893/Documents/
Just copying over the new sqlite to the apps folder where the old sqlite was present did not work. Copying it to the above mentioned folders fixed it for the simulator.
Now, when I connect to my ios device though, it cant find the new sqlite. If I copy back the old sqlite to the apps folder, it still works but copying the new one to the apps folder, the various destinations for the simulator etc has no effect on the ios device.
Displaying the path where it is looking at shows :
/var/mobile/Containers/Data/Application/80302FBA-6D45-4843-A891-E10A7ED4D445/Documents/CoreData.sqlite
Any help on where the device is picking the sqlite from? Since it works on the simulator and the older one works on the device also, the code seems ok. What can I do to get it to pick my new sqlite?
Device will pick the files from mainBundle. While doing database related functionality we copy the db files from mainBundle to DocumentDirectory, so that it becomes editable.
What you did was that you manually copied the sqlite file to the app data document folder. You should actually add the file to specific target and then it will copy the file during build process.
Your new coredata.sqlite file is not attached to any target. Check inside build phases and see if it is there, otherwise add it. Also you should not have two files with same name inside the bundle, so remove the previous file from target.
So basically I had an app extension (Today extension) in my project, then I created another one and deleted the first one. The deleted target isn't shown anywhere in the project, neither listed under "Targets" in the main project file, however, it is still compiling and showing up on the tests, both on the phone and on the simulator, even if I delete the app and reinstall it.
The major problem? Well, now I've changed the bundle id for both projects (the main app, and the app extension I created before), the project compiles but claims it can't be installed because:
"This app contains an app extension with an illegal bundle identifier. App extension bundle identifiers must have a prefix consisting of their containing application's bundle identifier followed by a '.'."
Although the remaining app extension bundle is correct, and matching this requirement. I'm pretty sure it is talking about the deleted target which now I can't configure. What can I do?
Thanks in advance :)
I fixed it by doing the following:
Find your project's .xcodeproj file.
Right click the it and select 'Show Package Contents'.
Navigating to root_dir.xcuserdatad/xcschemes/
Delete the offending .xcscheme file.
Restart xcode and it should be gone.