Publish Message Not working

I have app with App-ID “5F3BA2F5-9BAA-E70F-FF7E-CDA02D820600”
Have uploaded the .p12 certificates to the settings (dev version)
Recreated profiles and running the build i get token which is then saved to the backendless platform. I can see it in the devices section.
However when i go to publish a message to all iOS devices - the message is neither received nor shown in the messages tab. Only popup i get is message scheduled.
Any help on debugging ?

Hi Kim,

Just to be sure: have you followed all the instructions from the documentation: https://backendless.com/documentation/messaging/ios/messaging_push_notification_setup_ios.htm ?

Kim, did you set the provisioning profile for your app bundle identifier with push notification is switched on?

Hey guys

The attached screenshot might help of my provisioning profile.
I do have the .p12 file uploaded with the relevant certificate and correct bundle id.

Any update ?

Kim, please investigate the sample project in attachment. It works fine for me. Load it using TestPushNotify.xcworkspace. You could change Bundle Identifier to one for your .p12, set appId & secretKey of your Backendless app (with uploaded .p12 ), and try it with your app. Let we know how it goes.

TestPushNotify.zip (19.54MB)

Hi,

The project you uploaded doesnt really work with Xcode 8. Breakpoints and log do not hit so instead i tried debugging mine - revoking certificate and provisioning stuff. It still didnt work.

Then i went ahead and used https://github.com/noodlewerk/NWPusher to test it locally myself and well it works!
I used the same .p12 i uploaded on backendless.

Something is wrong with backendless sdk push. I can attach my code for you to check but you guys need to tell how this can be debugged from your end ?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
      
        self.setWindowAppearance()
        Backendless.sharedInstance().initApp("xxx", secret: "xxx", version: "v1")
        backendless.userService.setStayLoggedIn(true)
        backendless.messaging.registerForRemoteNotifications()
        ....
      }
 func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
        UIApplication.sharedApplication().registerForRemoteNotifications()
    }
    
    
    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
        print(error.localizedDescription)
    }
    
    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        let tokenChars = UnsafePointer<CChar>(deviceToken.bytes)
        var tokenString = ""
        
        for i in 0..<deviceToken.length {
            tokenString += String(format: "%02.2hhx", arguments: [tokenChars])
        }
        
        print("tokenString: \(tokenString)")
        backendless.messaging.registerDeviceToken(deviceToken)
        let currentInstallation = PFInstallation.currentInstallation()
        currentInstallation.setDeviceTokenFromData(deviceToken)
        currentInstallation.saveInBackgroundWithBlock(nil)
    }

Your code is absolutely wrong. This is a right one:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {


    var window: UIWindow?
    
    let APP_ID = "...."
    let SECRET_KEY = "...."
    let VERSION_NUM = "v1"
    
    var backendless = Backendless.sharedInstance()
    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
        backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
        
        return true
    }
    
    func applicationWillTerminate(application: UIApplication) {
        backendless.messaging.applicationWillTerminate()
    }
    
    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        backendless.messaging.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)
    }
    
    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
        backendless.messaging.didFailToRegisterForRemoteNotificationsWithError(error)
    }
    
    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        backendless.messaging.didReceiveRemoteNotification(userInfo)
    }
    
    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
        backendless.messaging.didReceiveRemoteNotification(userInfo)
        completionHandler(.NewData)
    }
    
}

Still the app does not receive the message from the backendless

  func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
        UIApplication.sharedApplication().registerForRemoteNotifications()
    }
    
    
    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
        print(error.localizedDescription)
    }
    
    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        let tokenChars = UnsafePointer&lt;CChar&gt;(deviceToken.bytes)
        var tokenString = ""
        
        for i in 0..<deviceToken.length {
            tokenString += String(format: "%02.2hhx", arguments: [tokenChars])
        }
        
        print("tokenString: \(tokenString)")
        backendless.messaging.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)
        let currentInstallation = PFInstallation.currentInstallation()
        currentInstallation.setDeviceTokenFromData(deviceToken)
        currentInstallation.saveInBackgroundWithBlock(nil)
    }
    
    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        AudioServicesPlayAlertSound(1110)
        backendless.messaging.didReceiveRemoteNotification(userInfo)
        NSNotificationCenter.defaultCenter().postNotificationName("displayMessage", object: userInfo)
        NSNotificationCenter.defaultCenter().postNotificationName("reloadMessages", object: nil)
    }
    
    
    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
        backendless.messaging.didReceiveRemoteNotification(userInfo)
        completionHandler(.NewData)
    }


Kim, could you please follow Vyacheslav’s suggestion from here? I see a lot of differences between your latest code and what he suggested.

I have actually followed his suggestion

changed backendless.messaging.registerDeviceToken(deviceToken)

to

backendless.messaging.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)

and added few other receive remote notification thing. I am already experienced with iOS development so i know error function didFailToRegisterForRemoteNotificationsWithError call isnt really helpful here since i already get the token call back and it is registered in the db. Now i close the app and when i send the message from the backendless console i do not receive the message while i do get it from the NWPusher.
No code really matters for a app that is in killed state/not running. Its the server side part - you send the notification from the server to APNS and then in the device the OS shows the push.

The code i previously had was also following the doc which Vyacheslav said is completely wrong so i would suggest to please update the doc and also test the part and help me resolve it. I am able to get the push from a other service but not yours.

Hi Kim,

I am certainly not questioning your iOS skills, just covering all the bases.

Please let me know what kind of certificate did you deploy through Backendless console? Is it Sandbox or the universal one (prod/sandbox)?

Along with that question, does the provisioning profile on the client side match the certificate? For example, if the certificate is universal, but the prov.profile is for sandbox, it will not work as they client will talk to different APNS servers than the backendless backend.

Regards,
Mark

Hi Mark,
No problem about that confusion.

I have uploaded the sandbox certificate on backendless yesterday and i am using the dev profile my side. Attached is a pusher screenshot that shows the connection successful after i import the .p12

provisioning profile was recreated yesterday as well.

Hi Kim,

How do you publish messages using Backendless? is it with the API or using Backendless console? Either way, what do the headers that you publish look like?

Regards,
Mark

Hey

Please find attached image of how i am pushing the message.

Thanks

Hi Kim,

Is the goal to publish a pub/sub message or a push notification?

Regards,
Mark

Send a push notification to device.

When you send a push notification, you also need to specify message headers as documented at:

https://backendless.com/documentation/messaging/ios/messaging_publish_push_notifications.htm

Can you give an example please.

That doc only gives example of sending message with headers in swift. No working example to test from the console.

Here is a sample how to publish a message:

class ViewController: UIViewController, IBEPushReceiver {
    
    var backendless = Backendless.sharedInstance()
    
    override func viewDidLoad() {
        super.viewDidLoad()


        backendless.messaging.notificationTypes = UIUserNotificationType.Alert.rawValue | UIUserNotificationType.Sound.rawValue | UIUserNotificationType.Badge.rawValue
        
        backendless.messaging.registerDeviceWithChannels(["testing"])
        backendless.messaging.pushReceiver = self
    }
    
    func publish() {
        
        print("PUBLISHED")
        
        let publishHeaders = [
            "publisher_name":"Tester",
            "ios-badge":"1",
            "ios-sound":"default",
            "ios-content-available":"1",
            "android-content-text":"Content text",
            "android-content-title":"Title",
            "android-ticker-text":"Ticker text"
        ]
        
        let publishOptions = PublishOptions()
        publishOptions.assignHeaders(publishHeaders)
        
        let deliveryOptions = DeliveryOptions()
        deliveryOptions.pushPolicy(PUSH_ONLY)
        deliveryOptions.pushBroadcast(FOR_ANDROID.rawValue|FOR_IOS.rawValue)
        
        backendless.messaging.publish(
            "testing",
            message: "ONE",
            publishOptions: publishOptions,
            deliveryOptions: deliveryOptions,
            response: {(status: MessageStatus!) -> () in
                print("Message has been sent: \(status)")
            },
            error: { (fault : Fault!) -> () in
                print("Server reported an error: \(fault)")
        })
    }
    
    // IBEPushReceiver Methods
    
    func didReceiveRemoteNotification(notification: String!, headers: [NSObject : AnyObject]!) {
        print("RECEIVED: \(headers["publisher_name"]) -> \(notification)")
    }
    
    func didRegisterForRemoteNotificationsWithDeviceId(deviceId: String!, fault: Fault!) {
        
        if fault == nil {
            print("didRegisterForRemoteNotificationsWithDeviceId: \(deviceId)")
            
            publish()
        }
        else {
            print("didRegisterForRemoteNotificationsWithDeviceId: \(fault)")
        }
    }
    
    func didFailToRegisterForRemoteNotificationsWithError(err: NSError!) {
        print("didFailToRegisterForRemoteNotificationsWithError: \(err)")
    }
}