无法将图片加载到Firebase(无法识别的选择器)

时间:2016-07-05 17:05:25

标签: ios swift3 firebase-storage

(顺便说一句,我已经阅读了所有关于SO的类似问题,请不要怪我,如果我的错误是愚蠢的)

我正在尝试上传图片,我从imagePicker获得并调整大小

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        process(pickedImage)
    }
    dismiss(animated: true, completion: nil)
}

func process(_ image:UIImage) {
    print("start processing")
    let resized = resize(image, size: 256)
    photo.image = resized
    let ref = FIRStorage.storage().reference().child("path/to/file")
    let data = UIImageJPEGRepresentation(resized, 1.0)
    let md = ref.put(data!)
    md.observe(.success, handler: { (snap) in
        //Something onSuccess
    })
}

func resize(_ image:UIImage, size w:CGFloat) -> UIImage {
    let scale = CGFloat(w)/image.size.width
    let newHeight = image.size.height * scale
    UIGraphicsBeginImageContext(CGSize(width: w, height: newHeight))
    image.draw(in: CGRect(x: 0, y: 0, width: w, height: newHeight))
    let newImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return newImage!
}

ref.put(data!)

上的抛出错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSConcreteURLComponents queryItems]: unrecognized selector sent to instance 0x1b093740'

完整堆栈跟踪(我希望,这就是你的意思)

 thread #1: tid = 0x87f6, 0x394161f0 libsystem_kernel.dylib`__pthread_kill + 8, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x394161f0 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x3947e7b6 libsystem_pthread.dylib`pthread_kill + 58
    frame #2: 0x393c6ff8 libsystem_c.dylib`abort + 76
    frame #3: 0x3881598e libc++abi.dylib`abort_message + 74
    frame #4: 0x3882e6e6 libc++abi.dylib`default_terminate_handler() + 254
    frame #5: 0x38e61f7c libobjc.A.dylib`_objc_terminate() + 192
    frame #6: 0x3882c1b2 libc++abi.dylib`std::__terminate(void (*)()) + 78
    frame #7: 0x3882ba08 libc++abi.dylib`__cxa_throw + 116
    frame #8: 0x38e61dba libobjc.A.dylib`objc_exception_throw + 250
    frame #9: 0x2e6ce836 CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 202
    frame #10: 0x2e6cd136 CoreFoundation`___forwarding___ + 706
    frame #11: 0x2e61c098 CoreFoundation`_CF_forwarding_prep_0 + 24
    frame #12: 0x0024758a ***APP_NAME***`__46-[FIRStorageMetadata dictionaryRepresentation]_block_invoke + 194
    frame #13: 0x2e60f3ce CoreFoundation`__53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 90
    frame #14: 0x2e60f300 CoreFoundation`-[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 232
    frame #15: 0x00247290 ***APP_NAME***`-[FIRStorageMetadata dictionaryRepresentation] + 532
    frame #16: 0x00246eac ***APP_NAME***`-[FIRStorageMetadata copyWithZone:] + 64
    frame #17: 0x38e6bcd8 libobjc.A.dylib`objc_setProperty_nonatomic_copy + 32
    frame #18: 0x0024d93e ***APP_NAME***`__31-[FIRStorageUploadTask enqueue]_block_invoke116 + 682
    frame #19: 0x004e5f22 ***APP_NAME***`__71-[GSDK_GTMSessionFetcher invokeOnCallbackQueue:afterUserStopped:block:]_block_invoke + 238
    frame #20: 0x3934ad52 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #21: 0x3934ad3e libdispatch.dylib`_dispatch_client_callout + 22
    frame #22: 0x3934d6c2 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 278
    frame #23: 0x2e695680 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #24: 0x2e693f4c CoreFoundation`__CFRunLoopRun + 1308
    frame #25: 0x2e5fe768 CoreFoundation`CFRunLoopRunSpecific + 524
    frame #26: 0x2e5fe54a CoreFoundation`CFRunLoopRunInMode + 106
    frame #27: 0x3356b6d2 GraphicsServices`GSEventRunModal + 138
    frame #28: 0x30f5d890 UIKit`UIApplicationMain + 1136
  * frame #29: 0x000945b8 ***APP_NAME***`main + 172 at AppDelegate.swift:11
    frame #30: 0x3935fab6 libdyld.dylib`start + 2

1 个答案:

答案 0 :(得分:1)

此处的问题是iOS 7不支持queryItems(我假设您正在定位)。下一个客户端版本将使用query属性来支持iOS 7。

与此同时,您可以定位8+,并且等待修复7时可以正常工作。