关于iCloud的注册 到代码的实现

移动开发 iOS
对于苹果的用户来说,iCloud可并不是一个网盘和保存联系人的工具那么简单,从2000年的iTools开始发展,一直到之前失败的2008年版MobileMe转型过来的iCloud已经发展出相当强大的功能。

iCloud需要xcode4.2 IOS5 sdk 请先做好准备工作:

[[52949]]

1.需要传件一个新的app id,要是有了一个的话,保证着个app id 不是一个通配符的那种。

2.创建完成之后,你要做的是开启这项功能,就跟开发推送一样,然后在创建一个新的Provisional Profile

3.选择工程的summary,滚动到entitlement点击entitlements,xcode会自动的创建一个*.entitlements

4.点击创建的*.entitlements,分别把pist列表里的三个字段都添上内容,格式为 (Team_ID.com.yourcompany.icloudtest),不要把team_id 跟 app_id弄混了啊,team_id是你创建完Provisional的时候,在最前面显示的那10个字符。

5.然后就可以在delegate里面写下面的代码了

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
  2.  { 
  3.  // Override point for customization after application launch. 
  4.  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
  5.  
  6. NSFileManager *fileManager = [NSFileManager defaultManager]; 
  7.  // Team-ID + Bundle Identifier 
  8.  NSURL *iCloudURL = [fileManager URLForUbiquityContainerIdentifier:@"ZZZZ826ZZ2.com.yourcompany.icloudtest"]; 
  9.  NSLog(@"%@", [iCloudURL absoluteString]); 
  10.  
  11. NSUbiquitousKeyValueStore *cloudStore = [NSUbiquitousKeyValueStore defaultStore]; 
  12.  [cloudStore setString:[iCloudURL absoluteString] forKey:@"iCloudURL"]; 
  13.  [cloudStore synchronize]; // Important as it stores the values you set before on iCloud 
  14.  
  15. 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))]; 
  16.  myLabel.font = [UIFont fontWithName:@"Marker Felt" size:round(self.window.bounds.size.width/20.0)]; 
  17.  myLabel.numberOfLines = 4
  18.  myLabel.text =[ @"iCloudURL=" stringByAppendingFormat:@"%@", [cloudStore stringForKey:@"iCloudURL"]]; 
  19.  myLabel.backgroundColor = [UIColor clearColor]; 
  20.  myLabel.textColor = [UIColor whiteColor]; 
  21.  myLabel.textAlignment = UITextAlignmentCenter
  22.  [self.window addSubview:myLabel]; 
  23.  
  24. [self.window makeKeyAndVisible]; 
  25.  return YES; 
  26.  } 

 

DEMO下载: iCloudTest

责任编辑:佚名 来源: Cocoachina
相关推荐

2012-02-15 09:43:43

iCloud云计算苹果

2021-10-04 18:59:41

苹果iCloudSafari书签

2013-10-18 09:50:58

2015-06-12 10:27:46

2022-05-06 07:52:06

Nacos服务注册

2015-03-12 09:51:09

CoreDataiCloud

2021-08-24 19:01:30

苹果iCloud邮件CSAM

2015-09-14 09:28:47

2022-08-01 07:38:29

代码开发

2015-08-13 10:54:46

2012-11-05 10:08:01

苹果iCloud云应用

2015-08-13 10:28:07

Cobjc_msgSen汇编

2010-06-07 14:05:38

Linux串口测试工具

2022-11-04 08:22:14

编译代码C语言

2011-08-31 16:39:06

Lua调试器

2017-04-10 18:10:31

2018-01-12 15:00:50

iCloudApple ID云服务

2011-11-24 11:24:45

iCloud云计算苹果

2022-04-06 09:10:40

映射器代理类接口

2018-04-08 15:40:09

Java代码优化
点赞
收藏

51CTO技术栈公众号