CFStringRef 类型转NSString类型使用 需要使用 __bridge,一定要记住

来源:互联网 发布:windows 优盘启动 编辑:程序博客网 时间:2024/06/02 02:18
最近在做imagePickerController时用到

extern constCFStringRef kUTTypeImage 但在强转成NSString*时一直不成功,后来就直接使用public image,今天在看其他例子时发现别人是这么用的

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

{

    if ([[infoobjectForKey:UIImagePickerControllerMediaType]isEqualToString:(__bridgeNSString *)kUTTypeImage]) {

        UIImage *img = [infoobjectForKey:UIImagePickerControllerEditedImage];

        [selfperformSelector:@selector(saveImage:) withObject:img afterDelay:0.5];

    }

    elseif ([[info objectForKey:UIImagePickerControllerMediaType]isEqualToString:(__bridgeNSString *)kUTTypeMovie]) {

        NSString *videoPath = [[infoobjectForKey:UIImagePickerControllerMediaURL]path];

        self.fileData = [NSDatadataWithContentsOfFile:videoPath];

    }

//    [picker dismissModalViewControllerAnimated:YES];

    [picker dismissViewControllerAnimated:YEScompletion:nil];

}

后来恍然大悟,之前好像也记得有用过 __bridge来转的,这次真的见识了这个用法,一定要记住!

0 0