私のアプリは、以前に質問したアプリです。これは、アプリを開いた日数と同じ数の XML 項目を表示する XML パーサーです。私の質問は主に次のとおりです。バージョン 1.0 では、iCloud で何も設定していません。人気のため、まもなく iPad バージョンのアプリをリリースしますが、iPhone でしばらくアプリを使用していた人が、iPad バージョンで Day 1 にリセットされるのではないかと懸念しています。GitHub でMKiCloudSyncを見つけたので、アプリがすべてのデバイス間で常に同期されるように、これを実装するのは良いことではないかと考えました。もしそうなら、アプリのバージョン 1.1 に追加すると、既存のライブラリと自動的に同期されますか? それとも、最初に iPhone バージョンを更新し、同期させてから、iPad 用に入手する必要がありますか? 基本的には、同期を維持したいだけです。
NSUserDefault 値を格納するために使用する AppDelegate コードを次に示します。ただし、一部の NSUserDefaults は他のクラスで変更される可能性があります。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(3);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults integerForKey:@"totalDays"]) {
// if there is no value for the key, set it to 1
[defaults setInteger:0 forKey:@"totalDays"];
}
if (![defaults objectForKey:@"currentDate"]) {
[defaults setObject:@"32 01" forKey:@"currentDate"];
}
if (! [defaults boolForKey:@"marked"]) {
[defaults setBool:NO forKey:@"marked"];
}
if (![defaults arrayForKey:@"checkedrows"]) {
NSMutableArray *arr1 = [NSMutableArray arrayWithArray:[defaults arrayForKey:@"checkedrows"]];
}
NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"dd MM"];
NSString *dateString = [dateFormat stringFromDate:date];
[dateFormat release];
NSString *checkdate = [defaults objectForKey:@"currentDate"];
if (![dateString isEqualToString:checkdate]) {
NSInteger currentnumber = [defaults integerForKey:@"totalDays"];
[defaults setObject:dateString forKey:@"currentDate"];
[defaults setInteger:currentnumber+1 forKey:@"totalDays"];
}
[defaults synchronize];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"enteredfore");
NSDate *date = [NSDate date];
// format it
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"dd MM"];
// convert it to a string
NSString *dateString = [dateFormat stringFromDate:date];
// free up memory
[dateFormat release];
NSString *checkdate = [defaults objectForKey:@"currentDate"];
NSLog(@"hereitis%@", checkdate);
if (![dateString isEqualToString:checkdate]) {
NSInteger currentnumber = [defaults integerForKey:@"totalDays"];
NSLog(@"The current number is %i", currentnumber);
[[NSNotificationCenter defaultCenter] postNotificationName:@"EnteredForeground"
object:nil];
[defaults setObject:dateString forKey:@"currentDate"];
[defaults setInteger:currentnumber+1 forKey:@"totalDays"];
[defaults synchronize];
}
}
ありがとう