到目前为止我所拥有的是创建新本地文件并删除iCloud文件的代码.
是否可以重命名iCloud文档,以便它保留在iCloud中?
GarageBand可以做到.可以重命名iCloud歌曲.重命名完成后,歌曲仍然在iCloud中.然而,GarageBand是Apple应用程序,因此它可能使用私有api.
我目前的代码:
- (void)moveFrom:(NSURL*)sourceURL
moveTo:(NSString*)destinationName
completion:(void (^)())completion
{
MyDocument *document = [[MyDocument alloc] initWithFileURL:sourceURL];
[document openWithCompletionHandler:^(BOOL success)
{
NSURL *fileURL = [self.localRoot URLByAppendingPathComponent:destinationName];
DLog(@"Create %@", fileURL);
[document saveToURL:fileURL
forSaveOperation:UIDocumentSaveForCreating
completionHandler:^(BOOL success)
{
NSLog(@"Saved %@", fileURL);
[document closeWithCompletionHandler:^(BOOL success) {
// Delete the old document from a secondary thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^()
{
NSFileCoordinator* fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[fileCoordinator coordinateWritingItemAtURL:sourceURL
options:NSFileCoordinatorWritingForDeleting
error:nil
byAccessor:^(NSURL* writingURL) {
NSFileManager* fileManager = [[NSFileManager alloc] init];
[fileManager removeItemAtURL:writingURL error:nil];
DLog(@"Deleted %@", sourceURL); …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
[metaDoc openWithCompletionHandler:^(BOOL success) {
if (!success) {
NSLog(@"UH OH");
}
}];
Run Code Online (Sandbox Code Playgroud)
为什么这会回归NO?对我来说,即使在我身上,它也会回归NO
- (BOOL)loadFromContents:(id)contents
ofType:(NSString *)typeName
error:(NSError **)outError
Run Code Online (Sandbox Code Playgroud)
方法,我总是返回YES.
谢谢
我想构建一个基于 iCloud 的应用程序,可以在 Apple 平台、iOS 和 Mac 上运行。该应用程序将使用 iOS 上的 UIDocument 和 Mac 上的 NSDocument 来拥有基于文档的同步模型 - 在 iOS 上创建的文档将在 Mac 上可用,反之亦然。
我面临的具体问题是我想在两个应用程序上使用相同的 iCloud 容器。XCode 根据 App ID 为应用程序创建一个默认容器,两个应用程序的 ID 必须不同,因为这似乎是 Apple 的要求 - 没有两个应用程序可以具有相同的应用程序 ID,即使它们位于不同的平台上。
因此,我保留了默认创建的容器,并在 Mac 应用程序和 iOS 应用程序上添加了另一个容器。该应用程序似乎工作正常,我可以在两个应用程序中的正确位置创建一个新文件包,但我遇到了两个问题:
该容器未正确显示在 iCloud 设置管理屏幕中。在 XCode 的权利部分中,我将容器命名为com.mycompany.myapp.mycontainer两个应用程序中的容器。在 iOS 的设置屏幕(设置 -> 常规 -> 使用 -> 管理存储 -> 显示全部)中,我的应用程序被列为“mycontainer”,而不是我预期的应用程序的实际名称。是否可以在应用程序的 Info.plist 中提供名称和图标以使其正确列出?
我的 NSMetadataQuery 无法正常工作。我使用空应用程序模板制作了 iOS 应用程序,因此 Info.plist 未使用 CFBundleDocumentTypes 键正确设置,但我发现并修复了它。为了在 iOS 应用程序中触发 NSMetadataQuery,我使用:
[self.queryCloud setPredicate:[NSPredicate predicateWithFormat:@"%K like '*.myextension*'",NSMetadataItemFSNameKey]];
搜索范围设置如下: …
我有一个问题,我似乎无法dealloc UIDocument(在iCloud中使用)
运行NSMetaDataQuery后查找文件如下..
NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
_query = query;
[query setSearchScopes:[NSArray arrayWithObject:
NSMetadataQueryUbiquitousDocumentsScope]];
NSPredicate *pred = [NSPredicate predicateWithFormat:
@"%K == %@", NSMetadataItemFSNameKey, kFILENAME];
[query setPredicate:pred];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(queryDidFinishGathering:)
name:NSMetadataQueryDidFinishGatheringNotification
object:query];
[query startQuery];
Run Code Online (Sandbox Code Playgroud)
我处理我的查询
- (void)queryDidFinishGathering:(NSNotification *)notification {
NSMetadataQuery *query = [notification object];
[query disableUpdates];
[query stopQuery];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSMetadataQueryDidFinishGatheringNotification
object:query];
_query = nil;
[self loadData:query];
}
Run Code Online (Sandbox Code Playgroud)
然后加载或创建一个新文档.
- (void)loadData:(NSMetadataQuery *)query {
if ([query resultCount] == 1) {
NSMetadataItem *item = [query resultAtIndex:0];
NSURL *url = …Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用Core Data,并在以下代码部分中遇到罕见的崩溃
-(void) useDocument{
AFFormsCoreDataEngine* engine = [AFFormsCoreDataEngine sharedInstance];
if (![[NSFileManager defaultManager] fileExistsAtPath: [engine.formsDatabase.fileURL path]])
{
[engine.formsDatabase saveToURL: engine.formsDatabase.fileURL forSaveOperation: UIDocumentSaveForCreating completionHandler: ^(BOOL success){
// setup
}];
}
else if (engine.formsDatabase.documentState == UIDocumentStateClosed)
{
[engine.formsDatabase openWithCompletionHandler: ^(BOOL success){
// setup
}];
}
else if (engine.formsDatabase.documentState == UIDocumentStateNormal)
{
// setup
}
}
Run Code Online (Sandbox Code Playgroud)
这就是崩溃日志所说的:
Last Exception Backtrace:
0 CoreFoundation 0x371fd88f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x31272259 objc_exception_throw + 33
2 CoreFoundation 0x371fd789 +[NSException raise:format:] + 1
3 Foundation 0x32ce83a3 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] …Run Code Online (Sandbox Code Playgroud) 我有文件下载选项。当用户从我的应用程序下载文档时,我需要将其存储到已经安装在用户移动设备中的用户iCloud Drive中。我已经在Web和Xcode中都配置了iCloud,但是问题是我无法正确将文件复制到iCloud Drive。文件已成功下载,并且也已移至iCloud,但文件不会出现在iCloud Drive App中。这是我尝试的代码:
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.MyAppBundleIdentifier</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>iCloudDriveDemo</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
这是我的iCloud存储代码:
func DownloadDocumnt()
{
print("Selected URL: \(self.SelectedDownloadURL)")
let fileURL = URL(string: "\(self.SelectedDownloadURL)")!
let documentsUrl:URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!
let destinationFileUrl = documentsUrl.appendingPathComponent("Libra-\(self.SelectedDownloadFileName)")
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let request = URLRequest(url:fileURL)
let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil
{
if let statusCode = (response as? …Run Code Online (Sandbox Code Playgroud) 每当我从iCloud加载UIDocument时,我会像这样检查它的状态:
NSLog(@"Library loadFromContents: state = %d", self.documentState);
Run Code Online (Sandbox Code Playgroud)
在某些情况下,我收到了导致崩溃的8号或12号文件.我现在想知道8和12究竟是什么代表什么.据我所知,documentState是一个位字段,因此它有许多不同的标志.该文件表明:
enum {
UIDocumentStateNormal = 0,
UIDocumentStateClosed = 1 << 0,
UIDocumentStateInConflict = 1 << 1,
UIDocumentStateSavingError = 1 << 2,
UIDocumentStateEditingDisabled = 1 << 3 };
typedef NSInteger UIDocumentState;
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何在我的情况下解释这一点.我如何找出8和12代表什么?
我已经编写了在instagram上传图像的代码,如下所示:
CGRect rect = CGRectMake(20 ,20 , 200, 200);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *jpgPath = [documentsDirectory stringByAppendingPathComponent:@"after2sm.ig"];
NSString *fileURL = [NSString stringWithFormat:@"file://%@",jpgPath];
NSURL *igImageHookFile = [NSURL fileURLWithPath:fileURL];
self.dic.UTI = @"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[NSDictionary dictionaryWithObject:@"My Caption" forKey:@"InstagramCaption"];
[self.dic presentOpenInMenuFromRect:rect inView:self.view animated:YES];
Run Code Online (Sandbox Code Playgroud)
但是它会打开一个带有"instagram"选项的动作表,但是当我点击它没有任何反应时,请你帮助我
当使用 Xcode 12.5.1 和 IOS 14.5 部署目标遵循 UIDocumentPickerViewController 的现场 IOS 文档时,我收到错误:
Incorrect argument label in call (have 'forOpeningContentTypes:', expected 'forExporting:')
Run Code Online (Sandbox Code Playgroud)
关于现在应该如何使用 IOS UIDocumentPickerViewController 有什么建议吗?
我的代码除了:
// Create a document picker for directories.
let documentPicker =
UIDocumentPickerViewController(forOpeningContentTypes: [.folder])
documentPicker.delegate = self
Run Code Online (Sandbox Code Playgroud)
错误快照:
有关如何使用文档选择器的文档,请参见此处:
https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directories给出:
我有一个自定义子类,UIDocument用于存储我的应用程序的用户内容.我-[UIDocument updateChangeCount:UIDocumentChangeDone]直接打电话来跟踪对文档的更改.保存和加载工作正常,但文档永远不会自动保存.为什么会这样?
我有一个简单的模型对象,Location其中包含一些文本项和一个images : [UIImages]?. Location所以Codable我将文本位存储为 JSON,然后将图像写入相同的FileWrapper.
我的问题是如何存储图像文件和 [UIImage] 数组之间的关系。图像必须以相同的顺序返回。有没有办法可以连接到编码,以便数组被指向图像的 URL 替换?
或者,我应该始终将图像作为单独的文件(例如在缓存目录中)并将 [UIImage] 替换为 [URL]
我正在尝试使用以下代码将照片从我的应用程序导出到Instagram:
// Capture Screenshot
UIGraphicsBeginImageContextWithOptions(self.view.frame.size,self.view.opaque,0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
dic = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:igImageHookFile]];
dic.UTI = @"com.instagram.photo";
dic.annotation = [NSDictionary dictionaryWithObject:@"my caption" forKey:@"InstagramCaption"];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
} else {
NSLog(@"No Instagram Found");
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.它崩溃时出现以下错误:
2013-01-19 20:40:41.948 Ayat [12648:c07] *由于未捕获异常'NSInvalidArgumentException'而终止应用程序,原因:'* - [NSURL initFileURLWithPath:]:nil string parameter'
我不确定我是否正确:
1-保存jpgpath作为我拍摄的截图.
2-将"dic"文档传递给Instagram.
uidocument ×12
ios ×10
icloud ×6
iphone ×3
cocoa-touch ×2
instagram ×2
objective-c ×2
swift ×2
xcode ×2
cocoa ×1
core-data ×1
crash ×1
dealloc ×1
ios5 ×1
ios6 ×1
retain ×1
swift3 ×1
uidocumentpickerviewcontroller ×1
uikit ×1