Prepare for the xcode4.2 IOS5 sdk required by iCloud:
1. You need to upload a new app id. If you have one, ensure that the app id is not a wildcard.
2. After the creation is complete, you need to enable this function, just like development push, and then create a new Provisional Profile
3. Select the project's summary and scroll to entitlement and click entitlements. xcode will automatically create an *. entitlements
4. click *. entitlements: add the three fields in the pist list to the content in the format of Team_ID.com.yourcompany.icloudtest. Do not confuse team_id with app_id. When you have created Provisional, the top 10 characters.
5. Then you can write the following code in delegate.
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- // Override point for customization after application launch.
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- // Team-ID + Bundle Identifier
- NSURL *iCloudURL = [fileManager URLForUbiquityContainerIdentifier:@"ZZZZ826ZZ2.com.yourcompany.icloudtest"];
- NSLog(@"%@", [iCloudURL absoluteString]);
-
- NSUbiquitousKeyValueStore *cloudStore = [NSUbiquitousKeyValueStore defaultStore];
- [cloudStore setString:[iCloudURL absoluteString] forKey:@"iCloudURL"];
- [cloudStore synchronize]; // Important as it stores the values you set before on iCloud
-
- UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,round(self.window.bounds.size.height/4.0),self.window.bounds.size.width,round(self.window.bounds.size.height/8.0))];
- myLabel.font = [UIFont fontWithName:@"Marker Felt" size:round(self.window.bounds.size.width/20.0)];
- myLabel.numberOfLines = 4;
- myLabel.text =[ @"iCloudURL=" stringByAppendingFormat:@"%@", [cloudStore stringForKey:@"iCloudURL"]];
- myLabel.backgroundColor = [UIColor clearColor];
- myLabel.textColor = [UIColor whiteColor];
- myLabel.textAlignment = UITextAlignmentCenter;
- [self.window addSubview:myLabel];
-
- [self.window makeKeyAndVisible];
- return YES;
- }
Download DEMO: iCloudTest