Search code examples
iosrevmob

My app is now throwing errors after trying to implement RevMob


The Error I am getting is:

Cannot convert value of type '(NSError!) -> Void' to expected argument type '((Error?) -> Void)!

The code that is causing this error is

RevMobAds.startSessionWithAppID("<YOUR_APP_ID>",     
    withSuccessHandler: completionBlock, 
    andFailHandler: failureBlock)

Has anybody had this error when using RevMob before or have any ideas on how to fix? Thanks

The error that I am getting: Error Getting Thrown


Solution

  • You are probably using the new Xcode and Swift 3.0. There have been a few changes on how Objective-C is converted to swift.

    You only have to change the errorBlock code from what we have in our documentation to this:

    let errorBlock: ((Error?) -> Void)! = {error in   //  <==  only this line changed
        // check the error
        print(error)
    }
    

    and add the parameter name to the startSession call:

    RevMobAds.startSession(withAppID: "<YOUR_APP_ID>",   //  only this line changed
                                            withSuccessHandler: completionBlock,
                                            andFailHandler: errorBlock);