Notifcation On IOS

I would like to ask that when user like a photo of a another user , i would like to push a notification to the user . I saw this function , and i would like to ask that what is device id ? the user objectId ?









 

    func publishMessageAsPushNotificationAsync(message: String, deviceId: String) {

        

        let deliveryOptions = DeliveryOptions()

        deliveryOptions.pushSinglecast = [deviceId]

        

        let publishOptions = PublishOptions()

        publishOptions.headers = @{@"android-content-title":@"Notification title for Android",

            @"android-content-text":@"Notification text for Android"};

        

        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)")

            }

        )

    }

Device ID is what’s included into the DeviceRegistration object which you receive from the following API call:

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

Regards,
Mark

so when user started install the apps , i need to user register api to register the device id ?

What happen if user delete and reinstall the app , it will register the user again right ? and i just wanna push the notification to a certain user base on their names how can i do it ?

After reinstalling the application you must re-register device using Backendless API. Would it happen or not - depends on your code.

You can send a push notification targeting specific user using its deviceId received on registration. Here is a link to docs: https://backendless.com/documentation/messaging/ios/messaging_publish_push_notifications.htm
You can chain users name with it deviceId using afterRegister event handler - put there logic which would update the user which calls registerDevice() method, with deviceId. After that you’ll be able to take deviceId from Users table and send a push notification targeting this device.

i am a bit confused right now , sorry , i am trying to test the push notification but have not receive any here my code

 
 
 
 
 
 
 
 
 // PUSH NOTIFICATION 
 
 func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 
 
 backendless.messaging.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken) 
 
 
 
 } 
 
 
 
 func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 
 
 backendless.messaging.didFailToRegisterForRemoteNotificationsWithError(error) 
 
 print(error) 
 
 } 
 
 
 
 
 
 func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
 
 backendless.messaging.didReceiveRemoteNotification(userInfo) 
 
 
 
 print("NOTIFIED2") 
 
 
 
 
 } 
 
 
 
 func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { 
 
 backendless.messaging.didReceiveRemoteNotification(userInfo) 
 
 print(completionHandler) 
 
 print("NOTIFIED") 
 
 }


 
 
 
 
 
 
 
 
 
 
 
 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
 
 // Override point for customization after application launch. 
 
 backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM) 
 


 
 
 
 backendless.messaging.registerForRemoteNotifications() 
 
 
 
 
 
 
 
 
 navigationBarAttribute() 
 
 tabBarAttribute() 
 
 //Change Status To White 
 
 
 
 application.statusBarStyle = UIStatusBarStyle.LightContent 
 
 if backendless.userService.currentUser == nil { 
 
 
 
 
 


 
 let storyboard = UIStoryboard(name: "Main", bundle: nil) 
 
 let loginVC = storyboard.instantiateViewControllerWithIdentifier("loginVC") 
 
 self.window?.rootViewController = loginVC 
 
 
 
 }else { 
 
 
 
 
 
 stayLoggedIn() 
 
 } 
 
 return true 
 
 
 
 
 
 
 } 



Make sure that:

  1. Device is registered ( verify it on the console )
  2. The message you’re sending contains all necessary headers for IOS, as described in docs
  3. Backendless application has been properly configured for sending push notifications in “Mobile Settings” section of “Manage” tab

The next steps can be: trying our IOS samples; generating sample for push notifications; trying to reproduce it on Android device ( if it’s possible )

I am now trying with samples , pushnotify so when i type the message it should be shown on my console ? when i submit the message in pushnotify , it will give me a push notificaiton right but i am not receiving any

I check your pushnotify it works but why does it have banner or anything ?

OK i am ok now , just left the channel stuff . First time using push notification , sorry , if i ask too much . thanks .

Hi Khoo,

Please see this thread. As you can see this sample helped to fix the problems of another customer. You also could investigate it.

You could try our sample with my backendless app:

static NSString *APP_ID = @“7B92560B-91F0-E94D-FFEB-77451B0F9700”;

static NSString *SECRET_KEY = @“B9D27BA8-3964-F3AE-FF26-E71FFF487300”;
Do It work for you?

Then change appId & secretKey by your backendless app values, and try again - will it go fine? If not - probably your certificate is wrong.

Please make all these steps and let me know about the result.

Regards,
Slava

ya , i check my certificate , i notice the recently change in WWDC certicate that make certificate invalid so i download new WWDC certicate . That fixed my problem