如何访问保存到 CloudKit 的照片?
How to access saved photos to CloudKit?
我正在使用 CloudKit 并成功保存了一张照片,至少我认为我做到了,因为我不知道一种用户友好的方式来检查我是否正确。我问这些是在用户拍摄几张照片并使用 cloudKit 保存照片然后他删除应用程序的情况下,但理论上他仍然应该能够通过苹果提供的某种界面访问数据,我说的对吗?
这是我使用的核心:
- (void) saveToiCloudImageNamed: (NSString *)imageName andTimeCreated:(NSString *)timeCreated{
CKContainer *container = [CKContainer defaultContainer];
CKDatabase *privateDatabase = [container publicCloudDatabase];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths firstObject];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:imageName];
NSURL *fileUrl = [[NSURL alloc] initFileURLWithPath:fullPath];
CKAsset *photoAsset = [[CKAsset alloc] initWithFileURL:fileUrl];
CKRecord *record = [[CKRecord alloc] initWithRecordType:@"Photo"];
record[@"asset"] = photoAsset;
record[@"name"] = timeCreated;
[privateDatabase saveRecord:record
completionHandler:^(CKRecord *record, NSError *error) {
if (error==nil) {
NSLog(@"The save was successful");
//Do something
}else{
NSLog(@"Error saving with localizedDescription: %@", error.localizedDescription);
NSLog(@"CKErrorCode = %lu", (long)[error code]);
if ([error code]==CKErrorNetworkFailure) {
double retryAfterValue = [[error.userInfo valueForKey:CKErrorRetryAfterKey] doubleValue];
NSLog(@"Error code network unavailable retrying after %f", retryAfterValue);
// NSTimer *timer = [NSTimer timerWithTimeInterval:retryAfterValue
// target:self
// selector:@selector(testOutCloudKit)
// userInfo:nil
// repeats:NO];
// [timer fire];
}
}
}];
}
目前没有用于访问 CloudKit 数据的界面,除非您自己创建。也许您想改用 iCloud 文档。
当您保存到 public 数据库(如您在上面的示例中所做的那样)时,您可以使用 CloudKit 仪表板访问数据。但这只能由您的 Apple 开发者帐户中的会员访问。
我正在使用 CloudKit 并成功保存了一张照片,至少我认为我做到了,因为我不知道一种用户友好的方式来检查我是否正确。我问这些是在用户拍摄几张照片并使用 cloudKit 保存照片然后他删除应用程序的情况下,但理论上他仍然应该能够通过苹果提供的某种界面访问数据,我说的对吗?
这是我使用的核心:
- (void) saveToiCloudImageNamed: (NSString *)imageName andTimeCreated:(NSString *)timeCreated{
CKContainer *container = [CKContainer defaultContainer];
CKDatabase *privateDatabase = [container publicCloudDatabase];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths firstObject];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:imageName];
NSURL *fileUrl = [[NSURL alloc] initFileURLWithPath:fullPath];
CKAsset *photoAsset = [[CKAsset alloc] initWithFileURL:fileUrl];
CKRecord *record = [[CKRecord alloc] initWithRecordType:@"Photo"];
record[@"asset"] = photoAsset;
record[@"name"] = timeCreated;
[privateDatabase saveRecord:record
completionHandler:^(CKRecord *record, NSError *error) {
if (error==nil) {
NSLog(@"The save was successful");
//Do something
}else{
NSLog(@"Error saving with localizedDescription: %@", error.localizedDescription);
NSLog(@"CKErrorCode = %lu", (long)[error code]);
if ([error code]==CKErrorNetworkFailure) {
double retryAfterValue = [[error.userInfo valueForKey:CKErrorRetryAfterKey] doubleValue];
NSLog(@"Error code network unavailable retrying after %f", retryAfterValue);
// NSTimer *timer = [NSTimer timerWithTimeInterval:retryAfterValue
// target:self
// selector:@selector(testOutCloudKit)
// userInfo:nil
// repeats:NO];
// [timer fire];
}
}
}];
}
目前没有用于访问 CloudKit 数据的界面,除非您自己创建。也许您想改用 iCloud 文档。
当您保存到 public 数据库(如您在上面的示例中所做的那样)时,您可以使用 CloudKit 仪表板访问数据。但这只能由您的 Apple 开发者帐户中的会员访问。