Rxswift: RxExtension UIImagePickerController: didFinishPickingMediaWithInfo not called.

Created on 8 Jan 2019  路  6Comments  路  Source: ReactiveX/RxSwift

Short description of the issue:
I'm using ImagePicker Extension for the reactive UIImagePickerViewController. But, the problem is that nothing is returned in any event (onNext,Error,.. etc).

Expected outcome:
Expected info Dictionary of type [IImagePickerController.InfoKey : Any]

Actual Output
None of the event gets triggered..!
(onNext, onError, onCompleted, onDisposed) None is triggered.

Code 13 Error logged in console.
screen shot 2019-01-09 at 10 49 38 am

Library Versions
RxSwift -> 4.4.0
RxCocoa -> 4.4.0

  startBtn.rx.tap
            .flatMapLatest { [weak self] _ in //1 tap -> picker
                return UIImagePickerController.rx.createWithParent(self) { picker in
                    picker.sourceType = .photoLibrary
                    picker.allowsEditing = false
                    } //2 -> info
                    .flatMap { $0.rx.didFinishPickingMediaWithInfo }
                    .take(1)


            }.subscribe(onNext: { (info) in
                print(info)
            }, onError: { (err) in
                print(err.localizedDescription)
            }, onCompleted: {
                print("completed")
            }) {
                print("disposed")
        }.disposed(by: disposeBag)


After some digging I found that didFinishPickingMediaWithInfo is not invoked in the extension of the Picker view

   public var didFinishPickingMediaWithInfo: Observable<[UIImagePickerController.InfoKey : Any]> {
        return delegate
            .methodInvoked(#selector(UIImagePickerControllerDelegate.imagePickerController(_:didFinishPickingMediaWithInfo:)))
            .map({ (a) in
                print("this is a \(a)") // Prints nothing.
                return try castOrThrow(Dictionary<UIImagePickerController.InfoKey, Any>.self, a[1])
            })
    }

Map block is not executed and nothing prints out.

Suggested Solution in Stack

 func imagePickerController(_ picker: UIImagePickerController, 
                           didFinishPickingMediaWithInfo info: [String : Any])

TO

 func imagePickerController(_ picker: UIImagePickerController, 
                           didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])

But no luck.

Does anyone has faced this problem? Help me out here..!

Most helpful comment

I had same problems, then after digging in Examples, i found out that i'm not implemented this :

RxImagePickerDelegateProxy.register { RxImagePickerDelegateProxy(imagePicker: $0) }

As seen in AppDelegate.

Now it's working as expected.

All 6 comments

You showed your expected output. What was the actual output? Did the subscription print "completed" or "disposed"?

I had same problems, then after digging in Examples, i found out that i'm not implemented this :

RxImagePickerDelegateProxy.register { RxImagePickerDelegateProxy(imagePicker: $0) }

As seen in AppDelegate.

Now it's working as expected.

@MegaGrindStone Thank you very much.

Damn! Finally! I spent 3hrs debugging this. Can someone provide background on this register, just curious why it's needed?

Also,

if you're adding RxImagePickerDelegateProxy.swift to your project, make sure you remove "open"

//
//  RxImagePickerDelegateProxy.swift
//  RxExample
//
//  Created by Segii Shulga on 1/4/16.
//  Copyright 漏 2016 Krunoslav Zaher. All rights reserved.
//
#if os(iOS)

import RxSwift
import RxCocoa
import UIKit

class RxImagePickerDelegateProxy
: RxNavigationControllerDelegateProxy, UIImagePickerControllerDelegate {

  public init(imagePicker: UIImagePickerController) {
    super.init(navigationController: imagePicker)
  }

}

#endif

However, I'm now stuch with this error:

Thread 1: Fatal error: Failure converting from Optional(<PartyTime.RxImagePickerDelegateProxy: 0x2810fa9e0>) to RxNavigationControllerDelegateProxy

:\

KUDOS to this guy!
http://www.hangge.com/blog/cache/detail_2037.html
銇┿亞銈傘亗銈娿亴銇ㄣ亞

I had same problems, then after digging in Examples, i found out that i'm not implemented this :

RxImagePickerDelegateProxy.register { RxImagePickerDelegateProxy(imagePicker: $0) }

As seen in AppDelegate.

Now it's working as expected.

It is good, get work.

Was this page helpful?
0 / 5 - 0 ratings