Subscribing to messageService while in airplane mode (wifi also disabled) crashes device


 private func subscribe(channel:String) {
 
 self.channelStatus = .Connecting
 
 let subscriptionOptions = SubscriptionOptions()
 
 // Set polling interval to two seconds
 BackendlessManager.sharedInstance.backendless.messagingService.pollingFrequencyMs = 2000
 
 BackendlessManager.sharedInstance.backendless.messagingService.subscribe(channel,
 subscriptionResponse: {(response : [AnyObject]!) -> () in
 //print ("Channel \(channel): response")
 
 let messages : [AnyObject] = response
 
 for object in messages {
 if object is Message {
 let message = object as! Message
 print ("message: \(message.data)")
 }
 }
 
 self.channelStatus = .Connected
 
 // Post channelStatus Notification
 NSNotificationCenter.defaultCenter().postNotificationName(kBLChannelStatus, object:self)
 
 },
 subscriptionError: { (fault : Fault!) -> () in
 print("Messaging Error (ASYNC): \(fault)")
 
 self.channelStatus = .Disconnected
 
 // Post channelStatus Notification
 NSNotificationCenter.defaultCenter().postNotificationName(kBLChannelStatus, object:self)
 
 // Try to reconnect
 self.start()
 },
 subscriptionOptions: subscriptionOptions)
 }

Calling this method while the iOS device is in airplane mode (and wifi disabled), the app crashes at line 40 (subscriptionOptions: subscriptionOptions)

Hi Barry,

What is your expectation when calling any of the network APIs (and this one in particular) when the device has no internet connection?

Regards,
Mark

Hi Mark,

Well the thing I don’t expect and surely not want is the application to crash. Even if I check if there is a connection available before calling it, the connection could have dropped just after the check and the method would still crash the app.

I expected a Fault with a code telling me that there is no internet connection.

What are your thoughts on this subject?

Hi Barry,

The same thing could happen inside of our implementation: check internet connection availability, then connection drops right before we do the call.

I agree with you that the fault block should be invoked if there is no connection. We will revisit the implementation to see if that can be done.

Regards,
Mark

Hi Mark,

Well other api’s just give a timeout when the connection drops while initiating / or transmitting data. So far I could never reproduce a crash while using networking libraries like Alamofire / AFNetworking / Starscream (we have tested a lot with unstable / dropping connections), maybe have a look at how they implemented it?

Thanks a lot,

Barry

Hi Mark,

Any update on this situation?

Thanks a lot,

Barry

Barry,

It is assigned to a developer to reproduce and to fix (if confirmed as a problem).

Regards,
Mark

Hi Mark,

Thanks for letting me know. Just for your info: You other network calls don’t crash when in airplane mode, even not when enabling airplane mode while calls are being made.

As a workaround I now check if there is a connection before trying to connect, but this should really not be necessary in my opinion.

Anyway: Thanks once again for you support!

Hi Barry,

So it is just the messaging calls that cause the problem?

Regards,
Mark

To be more exact: The call to messagingService.subscribe.

Everything else works perfectly so far.

This issue is fixed, you could update the latest Backendless SDK via CocoaPods (3.0.31 release) or from ios-SDK github (CommLibiOS and backendless).