Tôi đang sử dụng mã sau để tạo thư mục/tệp theo đường dẫn chứa được chia sẻ. Điều này sẽ giúp cả tiện ích mở rộng ứng dụng và tiện ích mở rộng chứa ứng dụng có thể truy cập dữ liệu.iOS8 Không thể tạo thư mục/tệp trong vị trí vùng chứa được chia sẻ của nhóm ứng dụng
mã để có được chia sẻ url chứa vị trí:
+(NSURL*)getSharedContainerURLPath
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *appGroupName = APP_EXTENSION_GROUP_NAME; /* For example */
NSURL *groupContainerURL = [fm containerURLForSecurityApplicationGroupIdentifier:appGroupName];
return groupContainerURL;
}
mã để tạo một thư mục
+(void)createDirAtSharedContainerPath
{
NSString *sharedContainerPathLocation = [[self getSharedContainerURLPath] absoluteString];
NSString *directoryToCreate = @"user_abc";
//basically this is <shared_container_file_path>/user_abc
NSString *dirPath = [sharedContainerPathLocation stringByAppendingPathComponent:directoryToCreate];
BOOL isdir;
NSError *error = nil;
NSFileManager *mgr = [[NSFileManager alloc]init];
if (![mgr fileExistsAtPath:dirPath isDirectory:&isdir]) { //create a dir only that does not exists
if (![mgr createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:&error]) {
NSLog(@"error while creating dir: %@", error.localizedDescription);
} else {
NSLog(@"dir was created....");
}
}
}
mã trên không gây bất kỳ lỗi nó nói thành công nhưng tôi không thể tìm thấy bên dưới đường dẫn vùng chứa được chia sẻ. Bất kỳ ý kiến cho rằng có thể được đánh giá cao
Khi bạn đã thiết lập Nhóm ứng dụng như được hiển thị trong liên kết sau. http://blog.parse.com/announcements/introducing-local-data-sharing-for-apple-watch-and-app-extensions/ – Thiru
hãy đánh dấu câu hỏi là được chấp nhận để mọi người biết đó là giải pháp @loganathan –
Nó làm việc cho tôi. Thanx – SPatel