Coder Social home page Coder Social logo

arturgrigor / cloudkitgdpr Goto Github PK

View Code? Open in Web Editor NEW
135.0 5.0 4.0 41 KB

Framework for allowing users to manage data stored in iCloud

License: MIT License

Swift 95.60% Ruby 2.42% Objective-C 1.98%
cocoapods swift xcode ios macos tvos watchos gdpr cloudkit icloud

cloudkitgdpr's Introduction

SPM compatible Carthage compatible Build Status CocoaPods Compatible Platform Twitter

CloudKitGDPR

Swift framework for allowing users to manage data stored in iCloud. This project is based on the sample code provided by Apple.

Requirements

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 3.0+
  • Xcode 10.2+
  • Swift 5.0+

Installation

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate CloudKitGDPR into your Xcode project using Carthage, specify it in your Cartfile:

github "arturgrigor/CloudKitGDPR" ~> 2.1

Run carthage update to build the framework and drag the built CloudKitGDPR.framework into your Xcode project.

❗️ Please note that since version 1.2 this is a Static Framework and it does not need to be included in the carthage copy-frameworks Build Phase. For more information please consult the Build static frameworks to speed up your app’s launch times section.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required.

To integrate CloudKitGDPR into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'CloudKitGDPR', '~> 2.1'
end

Then, run the following command:

$ pod install

Swift Package Manager

The Swift 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.

dependencies: [
    .Package(url: "https://github.com/arturgrigor/CloudKitGDPR.git", majorVersion: 2)
]

Usage

Create the instance

import CloudKitGDPR

let defaultContainer = CKContainer.default()
let documents = CKContainer(identifier: "iCloud.com.example.myexampleapp.documents")
let settings = CKContainer(identifier: "iCloud.com.example.myexampleapp.settings")

let metadata: GDPR.RecordTypesByContainer = [
  defaultContainer: ["log", "verboseLog"],
  documents: ["textDocument", "spreadsheet"],
  settings: ["preference", "profile"]
]

let maping: GDPR.ContainerNameMapping = [
  defaultContainer: "default",
  documents: "docs",
  settings: "settings"
]

let gdpr = GDPR(metadata: metadata, containerNameMapping: maping)

Export Data

Export all user's private data as JSON files.

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

gdpr.deleteData { result in
  switch result {
    case .failure(let error):
      print("GDPR delete data error: \(error)")

    case .success(_):
      // TODO: Maybe cleanup the local data too
      print("All user's private data deleted.")
    }
}

Advanced Usage

iOS

Export data as JSON files in a ZIP archive using the ZIPFoundation framework.

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: { data[$0..<$0+$1] })
        }

        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)
        }
      }
  }
}

Notes

iOS Demo Prerequisites

  • Change the identifier for the defaultContainer in the GDPR+App.swift file to one that's accessible to you.
  • Replace the "SomeRecordType" record type in the same file with one that's actually used in that container.
  • Use the same container identifier for the com.apple.developer.icloud-container-identifiers key in the Demo.entitlements file.

Contact

Let me know if you're using or enjoying this product.

cloudkitgdpr's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cloudkitgdpr's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.