Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing notifications in Sandbox #82

Open
SheepBroadcast opened this issue Dec 15, 2024 · 3 comments
Open

Testing notifications in Sandbox #82

SheepBroadcast opened this issue Dec 15, 2024 · 3 comments

Comments

@SheepBroadcast
Copy link

I've tried everything I could think of, looking at the docs, the examples, but I just can't get the library to work with development device tokens. Tried creating a UriFactory and setting the "sandbox" variable to true, but that didn't help. I validated my token through the Push Notifications console in my Apple Developer account, this is what the validator is giving me:
"Device Token is valid for sending Alert & Background push-type notifications in the Development environment"
But no matter what I try to push a test notification, this is what I always get:
"Failed to send notification: Bad device token."
Can I not use the development sandbox environment with this library?

@ZhukV
Copy link
Owner

ZhukV commented Dec 15, 2024

Hello @SheepBroadcast
Please provide code for test this issue, and screenshot where you test token.

Thank.

@SheepBroadcast
Copy link
Author

SheepBroadcast commented Dec 15, 2024

Hello @SheepBroadcast Please provide code for test this issue, and screenshot where you test token.

Thank.

try {
    $jwt = new Jwt($teamId, $keyId, $p8FilePath);
    $authenticator = new JwtAuthenticator($jwt);

    // Create device token
    $deviceToken = new DeviceToken($deviceTokenStr);

    // Uri factory
    $uriFactory = new UriFactory();
    $result = $uriFactory->create($deviceToken, true);

    // Build sender
    $builder = new Http20Builder($authenticator);
    $builder->setUriFactory($uriFactory);

    $protocol = $builder->buildProtocol();
    $sender = new Sender($protocol);

    $notification = Notification::createWithBody("Hello ;)");
    $receiver = new Receiver($deviceToken, $bundleId);

    $sender->send($receiver, $notification);

    $protocol->closeConnection();

    echo "Notification sent successfully!\n";
} catch (SendNotificationException $e) {
    // Handle errors when sending notification
    echo "Failed to send notification: " . $e->getMessage() . "\n";
} catch (Exception $e) {
    // Handle any other exceptions
    echo "Error: " . $e->getMessage() . "\n";
}

This is the code I am using. It's a simple php file running on my web server, that I then load via a browser. Excluded from the paste are my p8 file, the key id, the team id and the device token string, but they are defined and used in the code as you can see.

Edit: As for the screenshot you are requesting - I can't understand what you want me to screenshot?

@ZhukV
Copy link
Owner

ZhukV commented Dec 15, 2024

So, I should see you device token (without team id, key and private key), only you token for you device which you receive in you application. Why? Because in src/Model/DeviceToken.php, we full control pass correct token (why library should sent notification to invalid token?).

As for the screenshot you are requesting - I can't understand what you want me to screenshot?

You write previosly:

"Device Token is valid for sending Alert & Background push-type notifications in the Development environment"

But I don't understand, where you check this token, because our rules based on official documentation - only hex decimals.

You receive error: "Failed to send notification: Bad device token.". This error throwed only from apple side, no our side. As result, you should full check you team id, key id and device token.

P.S. You code is nice, and code does't have any problem. Please check correct pass all data (team id, private key, token) before sending notification. Maybe you use copy/paste for device token and lost few bytes....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants