skip to Main Content

I’ve followed the following tutorial to add Firebase to our iOS App https://rnfirebase.io/#3-ios-setup, however I keep getting the following error

Cannot convert value of type ‘UnsafeRawPointer’ to expected argument type ‘UnsafePointer<pb_byte_t>?’ (aka ‘Optional<UnsafePointer>’)

This is my Pod file

require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, min_ios_version_supported
prepare_react_native_project!

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'stllrmobile' do
  config = use_native_modules!

  use_frameworks! :linkage => :static
  #$RNFirebaseAsStaticFramework = true 

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming versions of React Native may rely on get_default_flags(), but
    # we make it explicit here to aid in the React Native upgrade process.
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    #:flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'stllrmobileTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

And this is the code line generating the error in SessionStartEvent.swift

func encodeDecodeEvent() -> firebase_appquality_sessions_SessionEvent {
    let transportBytes = self.transportBytes()
    var proto = firebase_appquality_sessions_SessionEvent()
    var fields = firebase_appquality_sessions_SessionEvent_fields

    let bytes = (transportBytes as NSData).bytes
    var istream: pb_istream_t = pb_istream_from_buffer(bytes, transportBytes.count)

    if !pb_decode(&istream, &fields.0, &proto) {
      let errorMessage = FIRSESPBGetError(istream)
      if errorMessage.count > 0 {
        Logger.logError("Session Event failed to decode transportBytes: (errorMessage)")
      }
    }
    return proto
  }

This is the line causing the error:

var istream: pb_istream_t = pb_istream_from_buffer(bytes, transportBytes.count)

Cannot convert value of type ‘UnsafeRawPointer’ to expected argument type ‘UnsafePointer<pb_byte_t>?’ (aka ‘Optional<UnsafePointer>’)

2

Answers


  1. I’ve upgraded from 10.3 to 10.6 and I’m hitting the same error as you with Unity build. Not sure how to fix it quite yet.

    Edit:
    I have modified this function a bit, given that it looks like it’s not supposedly used in actual production code. With this change the code compiles and seems to be running fine:

    /// Encodes the proto in this SessionStartEvent to Data, and then decodes the Data back into
    /// the proto object and returns the decoded proto. This is used for validating encoding works
    /// and should not be used in production code.
    func encodeDecodeEvent() -> firebase_appquality_sessions_SessionEvent {
      let transportBytes = self.transportBytes()
      var proto = firebase_appquality_sessions_SessionEvent()
      var fields = firebase_appquality_sessions_SessionEvent_fields
    
      let bytes = (transportBytes as NSData).bytes
      let bytes_pt: UnsafePointer<pb_byte_t> = bytes.assumingMemoryBound(to: pb_byte_t.self)
      var istream: pb_istream_t = pb_istream_from_buffer(bytes_pt, transportBytes.count)
    
      if !pb_decode(&istream, &fields.0, &proto) {
        let errorMessage = FIRSESPBGetError(istream)
        if errorMessage.count > 0 {
          Logger.logError("Session Event failed to decode transportBytes: (errorMessage)")
        }
      }
      return proto
    }
    

    Please note I have no idea if this cast for bytes_pt here is correct, as I’m not familiar with Swift.

    Login or Signup to reply.
  2. Firebase 9.x and 10.x require at least Xcode 13.3.1. See the release notes for additional detail.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search