未找到符号:kUTTypeImage

Symbol not found: kUTTypeImage

提问人:Lior Pollak 提问时间:4/14/2012 最后编辑:CodeBenderLior Pollak 更新时间:1/22/2022 访问量:39837

问:

我从苹果的文档中复制了一些代码 - 我得到了以下 2 个错误:

Undefined symbols for architecture i386:
  "_kUTTypeImage", referenced from:
      -[ImagePicker imagePickerController:didFinishPickingMediaWithInfo:] in ImagePicker.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我做错了什么?

编辑: 代码:

- (IBAction) showSavedMediaBrowser {
    [self startMediaBrowserFromViewController: self
                                usingDelegate: (id)self];
}

- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller
                               usingDelegate: (id <UIImagePickerControllerDelegate,
                                               UINavigationControllerDelegate>) delegate {

    if (([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
        || (delegate == nil)
        || (controller == nil))
        return NO;

    UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
    mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    // Displays saved pictures and movies, if both are available, from the
    // Camera Roll album.
    mediaUI.mediaTypes =
    [UIImagePickerController availableMediaTypesForSourceType:
     UIImagePickerControllerSourceTypeSavedPhotosAlbum];

    // Hides the controls for moving & scaling pictures, or for
    // trimming movies. To instead show the controls, use YES.
    mediaUI.allowsEditing = YES;

    mediaUI.delegate = delegate;

    [controller presentViewController:mediaUI animated:YES completion:nil];
    return YES;
}

- (void) imagePickerController: (UIImagePickerController *) picker
 didFinishPickingMediaWithInfo: (NSDictionary *) info {

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    UIImage *originalImage, *editedImage, *imageToUse;

    // Handle a still image picked from a photo album
    if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeImage, 0)
        == kCFCompareEqualTo) {

        editedImage = (UIImage *) [info objectForKey:
                                   UIImagePickerControllerEditedImage];
        originalImage = (UIImage *) [info objectForKey:
                                     UIImagePickerControllerOriginalImage];

        if (editedImage) {
            imageToUse = editedImage;
        } else {
            imageToUse = originalImage;
        }
        // Do something with imageToUse
    }

    [[picker parentViewController] dismissModalViewControllerAnimated: YES];
}

我认为错误是最后一种方法开始的地方,但我不确定。

您的帖子没有太多上下文来解释代码部分;请更清楚地解释您的情况。

iOS Objective-C 链接器错误 MobileCoreServices

评论

0赞 benc 2/11/2019
(这不是你的错)我已经阅读了我能找到的所有文档,他们谈到了使用 for ,但在他们的示例代码中,他们通常只是将值从一个函数传递到数组。他们从未在代码中实际使用它,也没有提到您需要导入它。UIImagePickerControllerkUT*mediaTypes

答:

202赞 justin 4/14/2012 #1

查找符号 () 并找到它应该存在于其中的图像/库(在本例中)。然后将二进制文件与该框架链接。kUTTypeImageMobileCoreServices.framework

评论

63赞 GreyHands 4/14/2012
另外,不要忘记导入标头 <MobileCoreServices/MobileCoreServices.h>
4赞 Lior Pollak 4/14/2012
工作!显然我链接了 CoreFoundation,而不是 MobileCoreServices。
1赞 Catalin 6/23/2016
或将@import MobileCoreServices;如果您不想导入框架并执行所有令人讨厌的工作
50赞 CodeBender 7/25/2016 #2

强制性 Swift 回答:

import MobileCoreServices
2赞 Sherwin Zadeh 5/20/2020 #3

与do一起使用时:UIDocumentPickerViewController

import MobileCoreServices

let type = String(kUTTypeImage)
let documentPickerViewController = UIDocumentPickerViewController(documentTypes: [type], in: .import)
2赞 Gerard 1/22/2022 #4

对于 Swift,它似乎在

import UniformTypeIdentifiers

let type = String(describing: UTType.image)