Backend\Core\Engine\Api::appleRemoveDevice PHP Method

appleRemoveDevice() public static method

Remove an Apple device from a user.
public static appleRemoveDevice ( string $token, string $email )
$token string The token of the device.
$email string The emailaddress for the user to link the device to.
    public static function appleRemoveDevice($token, $email)
    {
        trigger_error('The api is deprecated and will be removed in version 5', E_USER_DEPRECATED);
        if (BaseAPI::isAuthorized()) {
            // redefine
            $token = str_replace(' ', '', (string) $token);
            // validate
            if ($token == '') {
                BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No token-parameter provided.'));
            }
            if ($email == '') {
                BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No email-parameter provided.'));
            }
            try {
                // load user
                $user = new User(null, $email);
                // get current tokens
                $tokens = (array) $user->getSetting('apple_device_token');
                // not already in array?
                $index = array_search($token, $tokens);
                if ($index !== false) {
                    // remove from array
                    unset($tokens[$index]);
                    // save it
                    $user->setSetting('apple_device_token', $tokens);
                }
            } catch (Exception $e) {
                BaseAPI::output(BaseAPI::FORBIDDEN, array('message' => 'Can\'t authenticate you.'));
            }
        }
    }