1. 程式人生 > >友盟單點推送(推送給單個裝置)

友盟單點推送(推送給單個裝置)

public void sendIOSUnicast() throws Exception {
        IOSUnicast unicast = new IOSUnicast(appkey,appMasterSecret);
        // TODO Set your device token
        unicast.setDeviceToken("你的裝置token");
        unicast.setAlert("IOS 單播測試");
        unicast.setBadge( 0);
        unicast.setSound( "default");
        // TODO set 'production_mode' to 'true' if your app is under production mode
        unicast.setTestMode();
        // Set customized fields
        unicast.setCustomizedField("test", "helloworld");
        client.send(unicast);
    }


如上程式碼是友盟的demo中提供的,IOS裝置可以獲取到本機的device token,傳送到伺服器中儲存,每次想推送的時候直接呼叫上面的方法,在 setDeviceToken中設定為想要推送的裝置的deviceToken  友盟會自動推送到該裝置。