Can I use iCloud to sync the NSUserDefaults plist file
There is a library available to do this with one line of code
https://github.com/MugunthKumar/MKiCloudSync
How can i save NSData in iCloud
Yes it is possible. I have done that before and my answer is at syncing zip with iCloud,in which I am creating zip and converting it into NSData
and syncing with iCloud, later I am receiving NSData and again converting back it into zip and unzipping content. Here your main need is syncing of NSData so All you to have work around for NSData
.
1) Create subclass of UIDocument
#import <UIKit/UIKit.h>
@interface MyDocument : UIDocument
@property (strong) NSData *dataContent;
@end
2) MyDocument.m
#import "MyDocument.h"
@implementation MyDocument
@synthesize dataContent;
// Called whenever the application reads data from the file system
- (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError **)outError
{
self.dataContent = [[NSData alloc] initWithBytes:[contents bytes] length:[contents length]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"noteModified" object:self];
return YES;
}
// Called whenever the application (auto)saves the content of a note
- (id)contentsForType:(NSString *)typeName error:(NSError **)outError
{
return self.dataContent;
}
@end
3) Syncing with iCloud (You can do as per you need)
-(IBAction) iCloudSyncing:(id)sender
{
NSURL* ubiq = [[NSFileManager defaultManager]URLForUbiquityContainerIdentifier:nil];
NSURL *ubiquitousPackage = [[ubiq URLByAppendingPathComponent:@"Documents"] URLByAppendingPathComponent:@"iCloudPictures.zip"];
MyDocument *mydoc = [[MyDocument alloc] initWithFileURL:ubiquitousPackage];
NSData *data = << YOUR NSDATA >>;
mydoc.dataContent = data;
[mydoc saveToURL:[mydoc fileURL] forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success)
{
if (success)
{
NSLog(@"Synced with icloud");
}
else
NSLog(@"Syncing FAILED with icloud");
}];
}
Hope this helps..
Save user defaults to iCloud
You misunderstand what that is saying.
When a user backup's up their devices using iTunes or iCloud, only certain parts of the app's sandbox is backed up. So there are two important aspects here:
- Only backup data that can't be replaced.
- Be sure to backup irreplaceable data.
NSUserDefaults
is one of the things that will be backed up for you. You don't need to do anything special.
You don't need iCloud support unless your app has a specific need to use it.
Backing up NSUserDefaults and synching iPhone
Yes. NSUserDefaults uses a PLIST file as a backing store, which is backed up on each sync. See http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/UserDefaults/Concepts/DefaultsDomains.html for more information.
If you wanted to see for yourself, you could check out ~/Library/Application Support/MobileSync/Backup/. Create an unencrypted backup of a device with just your app on it, and view the files in the PLIST editor.
Related Topics
Gcd VS Performselectorinbackground/Performselectoronmainthread
Re-Authenticating User Credentials Swift
Are Cookies in Uiwebview Accepted
iOS 11 Large Navigation Bar Title Unexpected Velocity
Are Afnetworking Success/Failure Blocks Invoked on the Main Thread
Slservicetypefacebook Setinitialtext Is Not Working
Modulename-Swift.H File Not Found in Xcode8
Convert String to Date Type in Swift 3
Autolayout Multiline Uilabel Cutting Off Some Text
How to Share Image in Instagramswift
How to Apply a Tintcolor to a Uiimage
Avaudioplayer Produces Lag Despite Preparetoplay() in Swift
How to Hide First Section Header in Uitableview (Grouped Style)