Dmytro Rostopira
Dmytro Rostopira

Reputation: 11165

Failed to load image to Firebase (unrecognized selector)

(BTW, I've read all similar questions on SO, please don't blame me, if my mistake is stupid)

I'm trying to upload image, that I get from imagePicker and resized then

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!
}

This throwing error on ref.put(data!)

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSConcreteURLComponents queryItems]: unrecognized selector sent to instance 0x1b093740'

Full stack trace (I hope, this is what you mean)

 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

Upvotes: 0

Views: 172

Answers (1)

Mike McDonald
Mike McDonald

Reputation: 15963

Issue here is that queryItems isn't supported on iOS 7 (which I assume you're targeting). The next client version will support iOS 7 by using the query property instead.

In the mean time, you can target 8+, and it will work, while waiting for a fix for 7.

Upvotes: 1

Related Questions