iOS:将照片从共享扩展名传递到主应用程序时出错。错误:无法确定URL是否由文件提供商管理

时间:2019-07-09 10:12:45

标签: ios objective-c nsuserdefaults share-extension uiactivityitemprovider

当我单击“发布”按钮时,将照片从共享扩展程序传递到主应用程序时出现此错误消息:

 itemprovider = <NSItemProvider: 0x281f0e530> {types = (
    "public.jpeg"
)}
2019-07-09 12:03:38.343985+0200 SharePhotos[7558:233169] [default] [ERROR] Failed to determine whether URL /var/mobile/Media/PhotoData/OutgoingTemp/B037656F-3039-4124-9B97-6BF9B5FE1C2D/IMG_0317.JPG (s) is managed by a file provider
2019-07-09 12:03:38.361996+0200 SharePhotos[7558:233145] [User Defaults] Couldn't read values in CFPrefsPlistSource<0x281a2be00> (Domain: group.com.NewTelApps.GoFactDB, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
2019-07-09 12:03:38.363525+0200 SharePhotos[7558:233145] -[__NSDictionaryI attachments]: unrecognized selector sent to instance 0x2821864c0
2019-07-09 12:03:38.363792+0200 SharePhotos[7558:233145] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI attachments]: unrecognized selector sent to instance 0x2821864c0'
*** First throw call stack:
(0x204a30518 0x203c0b9f8 0x20494d278 0x204a35d60 0x204a379fc 0x205425820 0x100bd0ddc 0x2054c3810 0x204470a38 0x2044717d4 0x20441a320 0x20441ae3c 0x2044234a8 0x204651114 0x204653cd4)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

ShareViewController.m

- (BOOL)isContentValid {
    // Do validation of contentText and/or NSExtensionContext attachments here
    return YES;
}

- (void)didSelectPost {

    for (NSItemProvider* itemProvider in ((NSExtensionItem*)self.extensionContext.inputItems[0]).attachments ) {

        if([itemProvider hasItemConformingToTypeIdentifier:@"public.jpeg"]) {
            NSLog(@"itemprovider = %@", itemProvider);

            [itemProvider loadItemForTypeIdentifier:@"public.jpeg" options:nil completionHandler: ^(id<NSSecureCoding> item, NSError *error) {

                NSData *imgData;
                if([(NSObject*)item isKindOfClass:[NSURL class]]) {
                    imgData = [NSData dataWithContentsOfURL:(NSURL*)item];
                }
                if([(NSObject*)item isKindOfClass:[UIImage class]]) {
                    imgData = UIImagePNGRepresentation((UIImage*)item);
                }

                NSDictionary *dict = @{
                                       @"imgData" : imgData,
                                       @"name" : self.contentText
                                       };
                NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.NewTelApps.GoFactDB"];
                [defaults setObject:dict forKey:@"img"];                              
                [defaults synchronize];

                [self.extensionContext completeRequestReturningItems:@[dict] completionHandler:nil]; //CRASH
            }];
        }
    }
}

主要目标:
enter image description here 在共享扩展名:
enter image description here

我精确地说它已经起作用了,但是我确实犯了一个错误,破坏了整个过程,但无法知道它在哪里?

Info.plist中的配置:

它恰好在该行崩溃:

[self.extensionContext completeRequestReturningItems:@[dict] completionHandler:nil]; 

Docs

有什么想法吗?

0 个答案:

没有答案