Publishing Message also as Push

    Trying to publish a Message and also send out a Push to a channel simultaneously. However, it crashes every time I call this:
 func publishMessageAsPushNotificationAsync(message: String) {



 let deliveryOptions = DeliveryOptions()
 deliveryOptions.pushPolicy(PUSH_ALSO)



 let publishOptions = PublishOptions()
 publishOptions.addHeader("ios-sound", value: "mySound.aif")



 backendless.messaging.publish("default", message: message, publishOptions:publishOptions, deliveryOptions:deliveryOptions,
 response:{ ( messageStatus : MessageStatus!) -> () in
 print("MessageStatus = \(messageStatus.status) ['\(messageStatus.messageId)']")
 },
 error: { ( fault : Fault!) -> () in
 print("Server reported an error: \(fault)")
 }
 )

It crashes in the app delegate with no error or anything. I am able to do basic Push notifications (not involving the Message API), but I’d like to harness the power of pub/sub along with Push.

Does the program even go to this function? Have you tried running with a debugger to go through the code in a line-by-line manner to see where it breaks?

Yes, I am calling the method. When it gets called the debugger just breaks in the app delegate with no particular line. Even when I have break points enabled and step through the code.

When you step through the code, wouldn’t there be a specific line on which it breaks?

http://support.backendless.com/public/attachments/8ab1ea5e8332478dbed07e8625f0225d.png</img>

This is all it is giving me

it happens right on the start? Can you set a breakpoint on this line, for example:

let deliveryOptions = DeliveryOptions()

It hits the breakpoint at that line, and indeed enters the function:

http://support.backendless.com/public/attachments/7e96a20a23ea91fe5a2dcf16d1ea7cca.png</img>
However, it never does enter the response or error callback (neither of those print statements gets called).

What if you set breakpoints on lines 109 and 112. Does it stop on them?

No it does not get to those lines, even though it does get to 108. It seems right when it gets to 108 (the response), the crash in the appDelegate occurs.

Thanks. Just to make sure, do you have the backendless.initApp call in your AppDelegate?

Yes. Occasionally it won’t crash and the push / message will successfully publish. But most times it is giving me this crash.

Also, the messages console is empty even though I’m successfully publishing messages. They show up temporarily, but then it is empty:

http://support.backendless.com/public/attachments/6635cf301e9935f43002cdb53c25d8a1.png</img>

Could this be related?

The messages are ephemeral, they will be removed automatically a few minutes after they are published.

Could you try putting all the code between lines 107 and 114 into a try/catch block and see if you catch the exception that way?

How can I do a try / catch with this in Swift if the publish() method does not throw?

The underlying implementation is in Obj-C and there is an unhandled exception somewhere. I was hoping to be able to catch it in a simple way.

Sorry I’m unsure how to do a try / catch block in Swift; I’ve done it in Objective-C but Swift seems to require the function you try to be “throwable”, which publish() is not.

Could you please check if you’re using the latest library? You can get the most up to dat build from here:

I downloaded the SDK from here: https://backendless.com/downloads/

Should I be downloading it from the Github in the future? Is that more up-to-date than the downloads page on backendless.com?

Yes, the build in the git repo is more up to date than on the downloads page on the website.

I brought in the most recent lib and the crash still occurs