PHP iOS向特定用户推送通知

时间:2015-10-07 00:33:34

标签: php ios mysql objective-c notifications

我目前正在使用PushBots从PHP网站向iOS设备发送推送通知。我可以使用他们在注册推送通知后添加的设备令牌向特定用户发送通知(允许它)问题是,我想在发送时向特定用户(设备)发送推送通知直接消息(在网站上),但是在将推送通知注册到PushBots之后,我如何(或者可以)将设备令牌添加到我的MySQL数据库,因此推送通知可以在发送到特定用户(设备)之后发送直接消息。

这是PHP代码

<?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代码

- (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]);
}

0 个答案:

没有答案
相关问题