Hello.
I am using the following code in app delegate to register device:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
..
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
UIApplication.shared.registerForRemoteNotifications()
..
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
self.backendless?.messaging.registerDeviceToken(deviceToken, responder: nil)
}
and then the following method for subscribing to a channel (which runs successfully)
func subscribe() {
do {
let responder = Responder(responder: self, selResponseHandler: #selector(self.subscribeResponseHandler), selErrorHandler: #selector(self.subscribeErrorHandler))
let subscriptionOptions = SubscriptionOptions()
let subscription: BESubscription? = backendless?.messagingService.subscribe(“somenewchannelname”, subscriptionResponder: responder, subscriptionOptions: subscriptionOptions)
print("SUBSCRIPTION: \(subscription)")
} catch let fault {
print("FAULT = \(fault)")
}
}
and in business logic, i have deployed this code
@Asset( "UserPosts" )
public class UserPostsTableEventHandler extends com.backendless.servercode.extension.PersistenceExtender<UserPosts>
{
@Override
public void afterCreate( RunnerContext context, UserPosts userposts, ExecutionResult<UserPosts> result ) throws Exception
{
// add your code here
Celebs celeb = userposts.getCeleb();
String celebobjectid = celeb.getObjectId(); //this is the channel name
BackendlessUser user = userposts.getUser();
String msg = user.getProperty("name").toString() + " spotted " + celeb.getName().toString();
PublishOptions publishOptions = new PublishOptions();
MessageStatus status = Backendless.Messaging.publish(celebobjectid, (Object) msg, publishOptions );
}
}
this doesn’t send any notification to devices that are subscribed.
If i remove the channel name from the code in business logic and write instead:
MessageStatus status = Backendless.Messaging.publish((Object) msg, publishOptions );
then this runs successfully and sends a push notif to everyone.
What am i doing wrong here?