關(guān)于iCloud的注冊 到代碼的實現(xiàn)
iCloud需要xcode4.2 IOS5 sdk 請先做好準備工作:
1.需要傳件一個新的app id,要是有了一個的話,保證著個app id 不是一個通配符的那種。
2.創(chuàng)建完成之后,你要做的是開啟這項功能,就跟開發(fā)推送一樣,然后在創(chuàng)建一個新的Provisional Profile
3.選擇工程的summary,滾動到entitlement點擊entitlements,xcode會自動的創(chuàng)建一個*.entitlements
4.點擊創(chuàng)建的*.entitlements,分別把pist列表里的三個字段都添上內(nèi)容,格式為 (Team_ID.com.yourcompany.icloudtest),不要把team_id 跟 app_id弄混了啊,team_id是你創(chuàng)建完P(guān)rovisional的時候,在最前面顯示的那10個字符。
5.然后就可以在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;
- }
DEMO下載: iCloudTest