1

I am currently using PushBots to send push notifications to an iOS device from a PHP website. I can send notifications to a specific users by using their device token that is added after they register for push notifications (allowing it) The issue is that, I want to send a push notification to a specific user (device) when they're sent a direct message (on the website) but how do I (or is it possible to) add the device token to my MySQL database after push notifications are registered to PushBots, so push notifications can be sent to a specific user (device) after a direct message is sent.

Here's the PHP code

<?php

// Push The notification with parameters
require_once('PushBots.class.php');
$pb = new PushBots();
// Application ID
$appID = 'xxxxxxxxxxxxx';
// Application Secret
$appSecret = 'xxxxxxxxxxxxx';
$pb->App($appID, $appSecret);


$pb->AliasData(1, "xxxxxxxxxxxxx", "test");
// set Alias on the server
$pb->setAlias();

// Push it !
$pb->Push();

// Push to Single Device
// Notification Settings
$pb->AlertOne("New message from Skillet");
$pb->PlatformOne("0");
//device token of a specific device
$pb->TokenOne("xxxxxxxxxxxxx");

//Push to Single Device
$pb->PushOne();

?>

Objective-c code to register device token

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    //Handle notification when the user click it while app is running in background or foreground.
    [[Pushbots sharedInstance] receivedPush:userInfo];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // This method will be called everytime you open the app
    // Register the deviceToken on Pushbots
    [[Pushbots sharedInstance] registerOnPushbots:deviceToken];
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
    NSLog(@"Notification Registration Error %@", [error userInfo]);
}
PHP Web Dev 101
  • 535
  • 2
  • 9
  • 21

0 Answers0