Simple iCloud file managment.
Read, write, load, list files across devices, easily.
Before starting, please read Apple official reference: https://developer.apple.com/icloud/documentation/
- A valid Provisioning Profile ( with iCloud access )
- An iCloud account
- iOS 5.1+
- ARC / Non ARC
- iOS device
- Security.framework
Copy these files to your project:
APCloudCore.h
APCloudCore.m
APCloudDocument.h
APCloudDocument.m
APCloudFileSystem.h
APCloudFileSystem.m
APCloudData.h
APCloudData.m
NSString+MD5.h
NSString+MD5.m
and import Security.framework
to your project.
Import #import "APCloudCore.h"
in your project.
Next, set your delegate
, and your file prefix
.
File prefix, is very important if you want to separate files, because iCloud don't permit to create and read folders.
Every classes provides a singleton access.
[[APCloudCore sharedCloud] setDelegate:self];
[[APCloudCore sharedCloud] setFilePrefix:@"ap"];
[[APCloudCore sharedCloud] isCloudEnabled];
[[APCloudCore sharedCloud] saveData:yourData withName:yourFileName];
[[APCloudCore sharedCloud] loadDataWithName:yourFileName];
[[APCloudCore sharedCloud] deleteFileWithName:yourFileName];
[[APCloudCore sharedCloud] loadAllFilesWithPrefix:yourPrefix];
If you're implemented the optionals
delegate, you should implements the delegates (finish and fail):
- (void) apCloudCoreDidFinishUpdate;
- (void) apCloudCoreDidFailUpdate;
- (void) apCloudCoreDidFinishLoadFiles:(NSMutableArray*)file;
- (void) apCloudCoreDidFailLoadFiles;
- (void) apCloudCoreDidFinishSaveData:(id)data;
- (void) apCloudCoreDidFailSaveData:(id)data;
- (void) apCloudCoreDidFinishLoadData:(id)data;
- (void) apCloudCoreDidFailLoadData:(id)data;
- (void) apCloudCoreDidFinishDeleteData:(id)data;
- (void) apCloudCoreDidFailDeleteData:(id)data;
Save method, accept an id
as file. This id is your custom class, that must implements NSCoding
protocol.
Example of test store class:
@interface APTestStore : NSObject <NSCoding>
@property (nonatomic, strong) NSString *aTitle;
@property (nonatomic, strong) NSString *aSubTitle;
@property (nonatomic, strong) NSString *aDescription;
@end
@implementation APTestStore
@end
This class is saved (encrypted) and loaded (decrypted) to/from cloud as NSData
.
File are stored in your Cloud directory, that is accessibile from web, at url http://developer.icloud.com or in your Mac local folder, ~/Library/Mobile Documents/
.
Files are stored using this tree:
~/Library/Mobile Documents/XXXXXXX~it~albertopasca~dev-app/Documents/
ap_test-file-1.dat
ap_test-file-2.dat
ap_test-file-3.dat
xx-afile-1.dat
xx-afile-2.dat
[...]
"ap" or "xx" are the prefixes of your files!
Have fun.