Permalink
Browse files

Updated the `README.md` file and fixed an issue with `UIActivityViewC…

…ontroller` on iPad.
  • Loading branch information...
arturgrigor committed May 2, 2018
1 parent f501b6f commit 575696599ca957a6a89ee60aedf24d3a7b58dabb
Showing with 59 additions and 8 deletions.
  1. +3 −2 CloudKitGDPR iOS Demo/ViewController.swift
  2. +54 −4 README.md
  3. +1 −1 Sources/CSVDataTransformer.swift
  4. +1 −1 Sources/JSONDataTransformer.swift
@@ -68,14 +68,15 @@ class ViewController: UITableViewController {
let url = self.applicationCachesDirectory.appendingPathComponent("data.zip")
let archive = Archive(url: url, accessMode: .create)
for (fileName, csvContents) in value {
let data = Foundation.Data(bytes: Array(csvContents.utf8))
try? archive?.addEntry(with: fileName, type: .file, uncompressedSize: UInt32(data.count), provider: { position, size -> Foundation.Data in
let data = Data(bytes: Array(csvContents.utf8))
try? archive?.addEntry(with: fileName, type: .file, uncompressedSize: UInt32(data.count), provider: { position, size -> Data in
return data
})
}
DispatchQueue.main.async {
let viewController = UIActivityViewController(activityItems: [url], applicationActivities: [])
viewController.popoverPresentationController?.sourceView = self.exportDataCell
viewController.completionWithItemsHandler = { _, _, _, _ in
try? FileManager.default.removeItem(at: url)
}
View
@@ -35,7 +35,7 @@ Run `carthage update` to build the framework and drag the built `CloudKitGDPR.fr
### Swift Package Manager
The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but CloudKitGDPR does support its use on supported platforms.
The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but CloudKitGDPR does support its use on supported platforms.
Once you have your Swift package set up, adding CloudKitGDPR as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
@@ -79,13 +79,18 @@ gdpr.exportData(usingTransformer: JSONDataTransformer.default) { result in
switch result {
case .failure(let error):
print("GDPR export data error: \(error)")
case .success(let value):
print("User's private data: \(value)")
}
}
```
Supported transformers
- `ZeroDataTransformer`: This will give you the CloudKit records directly without any other transformation.
- `CSVDataTransformer`: This will give you a list of CSV files.
- `JSONDataTransformer`: This will give you a list of JSON files.
### Delete All Data ###
```swift
@@ -101,9 +106,54 @@ gdpr.deleteData { result in
}
```
## Advanced Usage
### iOS
Export data as JSON files in a ZIP archive using the [ZIPFoundation](https://github.com/weichsel/ZIPFoundation) framework.
```swift
import CloudKitGDPR
import ZIPFoundation
lazy var applicationCachesDirectory: URL = {
let urls = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)
return urls[urls.count-1]
}()
gdpr.exportData(usingTransformer: JSONDataTransformer.default) { result in
switch result {
case .failure(let error):
print("GDPR export data error: \(error)")
case .success(let value):
DispatchQueue.global(qos: .background).async {
let url = self.applicationCachesDirectory.appendingPathComponent("data.zip")
let archive = Archive(url: url, accessMode: .create)
for (fileName, csvContents) in value {
let data = Data(bytes: Array(csvContents.utf8))
try? archive?.addEntry(with: fileName, type: .file, uncompressedSize: UInt32(data.count), provider: { position, size -> Data in
return data
})
}
DispatchQueue.main.async {
let viewController = UIActivityViewController(activityItems: [url], applicationActivities: [])
viewController.popoverPresentationController?.sourceView = self.exportDataCell
viewController.completionWithItemsHandler = { _, _, _, _ in
try? FileManager.default.removeItem(at: url)
}
self.present(viewController, animated: true, completion: nil)
}
}
}
}
```
# Contact
- [GitHub](http://github.com/arturgrigor)
- [Twitter](http://twitter.com/arturgrigor)
- [GitHub](https://github.com/arturgrigor)
- [Twitter](https://twitter.com/arturgrigor)
Let me know if you're using or enjoying this product.
@@ -14,7 +14,7 @@ import CloudKit
//
/// CSV data transformer.
/// - Note: This data transformer will give you an array of CSV file contents.
/// - Note: This data transformer will give you a list of CSV files.
open class CSVDataTransformer: DataTransformer {
public typealias FileName = String
public typealias FileContents = String
@@ -14,7 +14,7 @@ import CloudKit
//
/// JSON data transformer.
/// - Note: This data transformer will give you an array of CSV file contents.
/// - Note: This data transformer will give you a list of JSON files.
open class JSONDataTransformer: DataTransformer {
public typealias FileName = String
public typealias FileContents = String

0 comments on commit 5756965

Please sign in to comment.