iCloud와 관련된 문제를 해결하려고합니다. 여기 내 코드에는 두 가지 버전이 있습니다.iCloud 키 - 값 동기화 iOS8 Xcode 6
- (void)viewDidLoad{
[super viewDidLoad];
[self checkICloudData];
}
버전은 1
- (void)checkICloudData
{
NSFileManager * fileManager=[NSFileManager defaultManager];
NSURL *iCloudURL=[fileManager URLForUbiquityContainerIdentifier:nil];
NSLog(@"iCloud URL is %@",[iCloudURL absoluteString]);
if (iCloudURL){
NSUbiquitousKeyValueStore * store=[NSUbiquitousKeyValueStore defaultStore];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateICloudData:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object:store];
[store synchronize];
}else{
NSLog(@"iCloud is not supported or enabled");
[self loadDataFromBundle];
}
}
iCloudURL 항상 전무를 반환합니다. 다른 방법은 호출하지 않습니다.
해당 버전의 아이 클라우드 동기화와 버전 2
- (void)checkICloudData
{
NSUbiquitousKeyValueStore * store=[NSUbiquitousKeyValueStore defaultStore];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateICloudData:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object:store];
[store synchronize];
}
- (void)updateICloudData:(NSNotification*)notification
{
NSDictionary *userInfo = [notification userInfo];
NSNumber *changeReason = [userInfo objectForKey:NSUbiquitousKeyValueStoreChangeReasonKey];
NSInteger reason = -1;
if (!changeReason) {
return;
} else {
reason = [changeReason integerValue];
}
if ((reason == NSUbiquitousKeyValueStoreServerChange) || (reason == NSUbiquitousKeyValueStoreInitialSyncChange)) {
NSArray *changedKeys = [userInfo objectForKey:NSUbiquitousKeyValueStoreChangedKeysKey];
for (NSString *key in changedKeys) {
if ([key isEqualToString:casesKey]) {
[self iCloudNotification];
}else {
[self loadDataFromBundle];
}
}
}
}
은 아이 패드와 함께 잘 작동하지만 아이폰이 작동하지 않습니다. 아이폰의 아이 클라우드 드라이브 설정에서 난 아이 패드
내 아이 클라우드 설정에서 같은 내 응용 프로그램은 동일한 참조 :
회원 센터 - 아이 클라우드가 활성화. 호환성 - CloudKit 지원을
대상 기능을 포함 - 서비스는 기본 자격 사전 만든
는 하늘의 배열과 키와 COM 키 com.apple.developer.icloud - 컨테이너 식별자를 포함에만 키 - 값 저장 확인 .apple.developer.ubiquity-kvstore 식별자
는
그럼, 왜 iCloudURL 항상 전무를 반환 내 APPID의 올바른 문자열 값? 그리고 두 번째 버전이 iPad에서 올바로 작동하는 이유는 무엇입니까?하지만 iPhone에는 NSUbiquitousKeyValueStoreDidChangeExternallyNotification이 표시되지 않습니다.