mcfly soft mcfly soft - 4 months ago 38
Swift Question

iCloud storage used by an app?

I published my app for reviewing in Applestore and I got a rejection, which says :

"
On launch and content download, your app stores 1.4 GB on the user's iCloud, which does not comply with the iOS Data Storage Guidelines.
"


I pasted the full rejection text in the end of the question.

I am not aware of storing data to the ICLoud and I am not sure how they test my app. They suggested to look in the settings for the ICloud storage, what I have done, but there I can't see any ICloud storage used by my app, when installed :

enter image description here

Is there any automatic process storing data from documents folder to the cloud after some time or setting ?

Generally my app is
- downloading a zipfile from my server to be stored in the Document folder of my app.
- Then the app is unzipping the zipfile also in the documents folder.

When testing with IOS-Simulator I can check the content of the document folder with a shell and the content is there. (and not on the ICloud)

Can someone help me , what a developer has to do in this case.

I pasted the relevant code here, which shows how I am downloading the content and how I am unzipping the content.

class ViewController: UIViewController, NSURLSessionDelegate {

let sDataPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString as String; ///var/mobile/Containers/Data/Application/8897ED62-5BAE-4255-8459-F0F8381C171F/Documents/
download_file(sfrom,sToLocation: sDataPath);


func download_file(sURL: String, sToLocation: String) {

print("start downloading ...");
print("sURL : " + sURL + " sToLocation : " + sToLocation);
bytesDownloaded=0;

let downloadsessiondelegate = self;
downloadsessiondelegate.storePath=sToLocation;
downloadsessiondelegate.progressView=progressView;
downloadsessiondelegate.surl=sURL;
struct SessionProperties {
static let identifier : String! = "url_session_background_download"
}
let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([.Hour, .Minute], fromDate: date)
let hour = String(components.hour)
let minutes = String(components.minute)


let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("session_" + hour + minutes)
let backgroundSession = NSURLSession(configuration: configuration, delegate: downloadsessiondelegate, delegateQueue: nil)
//myURLSession = NSURLSession(configuration: configuration, delegate: delegate, delegateQueue: nil)
let url = NSURLRequest(URL: NSURL(string: sURL)!)
//var downloadTask = backgroundSession.downloadTaskWithRequest(url)

let downloadTask = backgroundSession.downloadTaskWithRequest(url)
downloadTask.resume()
}




func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location1: NSURL) {
//println("session \(session) has finished the download task \(downloadTask) of URL \(location1).")

// remove Session ID
//defaults.removeObjectForKey(<#defaultName: String#>)
let defaults = NSUserDefaults.standardUserDefaults()
defaults.removeObjectForKey("SessionProperties_identifier" + "_" + surl)


var error: NSError?
let target=storePath;
var source : String = location1.absoluteString;
let filemgr = NSFileManager.defaultManager();

let modifiedsource = source.stringByReplacingOccurrencesOfString("file://", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)


if (filemgr.fileExistsAtPath(target))
{
do {
try filemgr.removeItemAtPath(target)
} catch let error1 as NSError {
error = error1
}
//println("FILE AVAILABLE");
}


do {
try filemgr.moveItemAtPath(modifiedsource, toPath: target)


dispatch_async(dispatch_get_main_queue(),{
self.progressView.setProgress(0, animated: false);
//progressView.removeFromSuperview();
print("Move successful")
self.install_content();
})



//download_file_finished();
} catch var error1 as NSError {
error = error1
print("Moved failed with error: \(error!.localizedDescription)")
install_failed("Moved failed with error: \(error!.localizedDescription)");
}

}



func unzipFile(sZipFile: String, toDest: String, estimatedByte:Int){

SSZipArchive.unzipFileAtPath(sZipFile, toDestination: toDest, progressHandler: {
(entry, zipInfo, readByte, totalByte) -> Void in

//let itotalByte=totalByte;
let stufe=4096*1000;
if totalByte % stufe == 0 {
//println("readByte : \(totalByte)")
}

dispatch_async(dispatch_get_main_queue()) {

var percent:Float=Float(Float(totalByte)/Float(estimatedByte));
if percent>1.0{
percent=1.0;
}
let percent_int=Int(percent*100);
let percenttext:String=String(percent_int);
self.progressView.setProgress(percent, animated: false);
let sMessage=self.actualinstalldefinition.title;

let messagewithprozent=sMessage + " (" + percenttext + "%)";

self.progress_label_Titel.text = messagewithprozent;

if percent_int % 20 == 0 && self.lastpercent != percent_int{
let progressimage=self.get_random_progress_image();
self.progressImageView.image = progressimage;
self.lastpercent=percent_int;
}

}

}, completionHandler: { (path, success, error) -> Void in
if success {
// Loesche das ZipFile
let fileManager = NSFileManager.defaultManager()

var error: NSError?
if (fileManager.fileExistsAtPath(sZipFile)){
do {
try fileManager.removeItemAtPath(sZipFile)
} catch let error1 as NSError {
error = error1
} catch {
fatalError()
}
}

dispatch_async(dispatch_get_main_queue(),{
self.progressView.setProgress(0, animated: false);
//progressView.removeFromSuperview();
print("Move successful")
self.install_content();
})

} else {
//progressBar?.hidden = true
self.install_failed(error.localizedDescription);
print(error)
}
})
}


Complete rejection statement :

2.23 - Apps must follow the iOS Data Storage Guidelines or they will be rejected


2.23 Details

On launch and content download, your app stores 1.4 GB on the user's iCloud, which does not comply with the iOS Data Storage Guidelines.

Next Steps

Please verify that only the content that the user creates using your app, e.g., documents, new files, edits, etc. is backed up by iCloud as required by the iOS Data Storage Guidelines. Also, check that any temporary files used by your app are only stored in the /tmp directory; please remember to remove or delete the files stored in this location when it is determined they are no longer needed.

Data that can be recreated but must persist for proper functioning of your app - or because users expect it to be available for offline use - should be marked with the "do not back up" attribute. For NSURL objects, add the NSURLIsExcludedFromBackupKey attribute to prevent the corresponding file from being backed up. For CFURLRef objects, use the corresponding kCRUFLIsExcludedFromBackupKey attribute.

Resources

To check how much data your app is storing:

- Install and launch your app
- Go to Settings > iCloud > Storage > Manage Storage
- Select your device
- If necessary, tap "Show all apps"
- Check your app's storage


For additional information on preventing files from being backed up to iCloud and iTunes, see Technical Q&A 1719: How do I prevent files from being backed up to iCloud and iTunes.

If you have difficulty reproducing a reported issue, please try testing the workflow described in Technical Q&A QA1764: How to reproduce bugs reported against App Store submissions.

If you have code-level questions after utilizing the above resources, you may wish to consult with Apple Developer Technical Support. When the DTS engineer follows up with you, please be ready to provide:
- complete details of your rejection issue(s)
- screenshots
- steps to reproduce the issue(s)
- symbolicated crash logs - if your issue results in a crash log

Answer

Files placed in the Documents folder are automatically backed up to iCloud.

The backup process may not start instantly which is why you do not see your app's iCloud storage.

Use this code to exclude a file from the auto backup.

try! filePath.setResourceValue(true, forKey: NSURLIsExcludedFromBackupKey)

See the docs for more information.