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

原文地址:点击打开链接



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

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里面写下面的代码了


- (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地址:下载demo









  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值