I'm working with Swift 5.0 and I want to zip 3 files without installing additional dependencies.
Currently I'm able to zip 3 Files, which all are in the same directory, called "root". But if I open the created and exported zip-file (named: final.zip), than I get the folder (root) in which the 3 files were saved. I don't want this "root" folder inside my final.zip. I want to see my data directly inside the final.zip
Below is the code.
let fm = FileManager.default
let baseDirectoryUrl = fm.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("root", isDirectory: true)
if !fm.fileExists(atPath: baseDirectoryUrl.relativePath) {
try! fm.createDirectory(
at: baseDirectoryUrl,
withIntermediateDirectories: true,
attributes: nil
)
}
// path of data
let data1_path = baseDirectoryUrl.appendingPathComponent("data1.vec3")
let data2_path = baseDirectoryUrl.appendingPathComponent("data2.vec3")
let data3_path = baseDirectoryUrl.appendingPathComponent("data3.json")
// write wData1 to data1_path
try! wData1.write(to: data1_path)
// write wData2 to data2_path
try! wData2.write(to: data2_path)
// write wData3 to data3_path
try! wData3.write(to: data3_path)
// this will hold the URL of the zip file
var archiveUrl: URL?
// if we encounter an error, store it here
var error: NSError?
let coordinator = NSFileCoordinator()
// zip up the root directory
// this method is synchronous and the block will be executed before it returns
// if the method fails, the block will not be executed though
// if you expect the archiving process to take long, execute it on another queue
coordinator.coordinate(readingItemAt: baseDirectoryUrl, options: [.forUploading], error: &error) { (zipUrl) in
// zipUrl points to the zip file created by the coordinator
// zipUrl is valid only until the end of this block, so we move the file to a temporary folder
let tmpUrl = try! fm.url(
for: .itemReplacementDirectory,
in: .userDomainMask,
appropriateFor: zipUrl,
create: true
).appendingPathComponent("export.zip", isDirectory: false)
try! fm.copyItem(at: zipUrl, to: tmpUrl)
// store the URL so we can use it outside the block
archiveUrl = tmpUrl
}
if let archiveUrl = archiveUrl {
// bring up the share sheet so we can send the archive with AirDrop for example
let avc = UIActivityViewController(activityItems: [archiveUrl], applicationActivities: nil)
avc.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
present(avc, animated: true)
} else {
print(error)
}
I'm glad for everybody who can help
Post
Replies
Boosts
Views
Activity
Hello,
I work with XCode 12.5 and Swift 5. I am a member of a development Team.
I finished my first App and I want to start with Beta Testing using Testflight. I already tested the app on my mobile device and everything works fine.
Furthermore I followed every step of this article:
https://developer.apple.com/documentation/xcode/preparing-your-app-for-distribution
This article describes the steps to distribute my App for Beta Testing:
https://developer.apple.com/documentation/xcode/distributing-your-app-for-beta-testing-and-releases
On of the first steps is creating an archive of my app. When I do this I don't get the option "Distribute App". I only get the option "Distribute Content".
The following distribution methods doesn't contain the options i need.
I already tried the solutions mentioned here:
https://stackoverflow.com/questions/55467829/xcode-10-1-doesnt-show-distribute-app-option-when-archiving-cant-archive
In this article it seems like the solution is to change the "skip install" value. I have the "Skip Install" once in the "Projects" and "Targets" section. I already tried each combination of ticking yes and no, but the result stays the same.
I also tried it with different provisioning profiles. Once with the Type "Development" and once with the type "Distribution".
This is the first app that i wrote and published through the App Store. It could be that i am missing out something obvious?
I am glad for everyone who can help me!
Thanks in advance
Jakob