firebase / FirebaseUI-iOS

iOS UI bindings for Firebase.
Apache License 2.0
1.52k stars 478 forks source link

sd_setImage crash when using Storage emulator #1114

Open AphroditeSoftware opened 2 years ago

AphroditeSoftware commented 2 years ago

Step 1: Are you in the right place?

I believe so.

Step 2: Describe your environment

Step 3: Describe the problem:

My code is trying to use sd_setImage to load an image stored in a Firebase Storage. I'm using the Firebase Emulator and have loaded some images in a folder in the emulator under, well, "images". I've attempted this both in my own app and in the sample app from FirebaseUI-demo.

Steps to reproduce:

Follow the instructions to set up to run the samples app locally. Added line to FUIAppDelegate.swift use the emulator:

Storage.storage().useEmulator(withHost:"localhost", port:9199)

Observed Results:

Crashes with exception:

2022-10-30 19:38:50.916495-0600 FirebaseUI-demo-swift[32333:257475] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FIRStorageTask fetcher]: unrecognized selector sent to instance 0x6000025169d0'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007ff800427378 __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007ff80004dbaf objc_exception_throw + 48
    2   CoreFoundation                      0x00007ff800436588 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
    3   CoreFoundation                      0x00007ff80042b83d ___forwarding___ + 1431
    4   CoreFoundation                      0x00007ff80042db38 _CF_forwarding_prep_0 + 120
    5   FirebaseStorageUI                   0x000000010fa5a6c0 __80-[FUIStorageImageLoader requestImageWithURL:options:context:progress:completed:]_block_invoke.53 + 128
    6   FirebaseStorage                     0x000000010fd6e889 $s15FirebaseStorage0B12TaskSnapshotCIeyBy_ACIegg_TR + 25
    7   FirebaseStorage                     0x000000010fd6e698 $s15FirebaseStorage0B14ObservableTaskC7observe_7handlerSSAA0bD6StatusO_yAA0bD8SnapshotCctFySo014FIRIMPLStoragedH0CcfU_ + 168
    8   FirebaseStorage                     0x000000010fd6e74a $sSo26FIRIMPLStorageTaskSnapshotCIegg_ABIeyBy_TR + 58
    9   FirebaseStorageInternal             0x000000010ff9db44 __54-[FIRIMPLStorageObservableTask fireHandlers:snapshot:]_block_invoke_2 + 36
    10  libdispatch.dylib                   0x00000001106c2d18 _dispatch_call_block_and_release + 12
    11  libdispatch.dylib                   0x00000001106c3f5b _dispatch_client_callout + 8
    12  libdispatch.dylib                   0x00000001106d4d55 _dispatch_main_queue_drain + 1463
    13  libdispatch.dylib                   0x00000001106d4790 _dispatch_main_queue_callback_4CF + 31
    14  CoreFoundation                      0x00007ff8003869f7 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    15  CoreFoundation                      0x00007ff8003813c6 __CFRunLoopRun + 2482
    16  CoreFoundation                      0x00007ff800380637 CFRunLoopRunSpecific + 560
    17  GraphicsServices                    0x00007ff809c0f28a GSEventRunModal + 139
    18  UIKitCore                           0x000000011bd9e425 -[UIApplication _run] + 994
    19  UIKitCore                           0x000000011bda3301 UIApplicationMain + 123
    20  FirebaseUI-demo-swift               0x000000010f1c316f main + 63
    21  dyld                                0x000000010f48d2bf start_sim + 10
    22  ???                                 0x000000011523052e 0x0 + 4649583918
)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FIRStorageTask fetcher]: unrecognized selector sent to instance 0x6000025169d0'
terminating with uncaught exception of type NSException
CoreSimulator 857.7 - Device: iPhone 14 Pro (2935292C-6CCB-4EB6-9B9B-58EA25365753) - Runtime: iOS 16.0 (20A360) - DeviceType: iPhone 14 Pro

The emulator log implies the fetch succeeded:

Starting DownloadTask

2022-10-31 01:38:50 +0000  elapsed: 0.054sec
Request: GET http://localhost:9199/v0/b/xxxxxx-3df69.appspot.com/o/images%2Fbess.jpg?alt=media
Request headers:
  User-Agent: com.google.firebase.firebaseui.FirebaseUI-demo-swift/1.0 iPhone/16.0 hw/sim
  x-firebase-gmpid: 1:1092111096994:ios:4fff06c4faedf6306c4bfb
  x-firebase-storage-version: ios/9.6.0

Response: status 200
Response headers:
  Accept-Ranges: bytes
  Access-Control-Expose-Headers: content-type,x-firebase-storage-version,x-goog-upload-url,x-goog-upload-status,x-goog-upload-command,x-gupload-uploadid,x-goog-upload-header-content-length,x-goog-upload-header-content-type,x-goog-upload-protocol,x-goog-upload-status,x-goog-upload-chunk-granularity,x-goog-upload-control-url
  Connection: keep-alive
  Content-Disposition: inline
  Content-Length: 537875
  Content-Type: image/jpeg
  Date: Mon, 31 Oct 2022 01:38:50 GMT
  Keep-Alive: timeout=5
  Vary: Origin
  X-Powered-By: Express

Response body: (537875 bytes)
<<537875 bytes>>

And using the URL in the browser succeeds as well, the photo is shown. http://localhost:9199/v0/b/xxxxxx-3df69.appspot.com/o/images%2Fbess.jpg?alt=media

Expected Results:

Image loads with no issues.

Relevant Code:

Added line in FUIAppDelegate.swift to use the emulator:

Storage.storage().useEmulator(withHost:"localhost", port:9199)

AphroditeSoftware commented 2 years ago

I've further isolated this to the use of .progressiveLoad in the option of sd_setImage(with: self.storageRef,. Without .progressiveLoad, the sample does not crash. With .progressiveLoad, it crashes.