Giter VIP home page Giter VIP logo

Comments (4)

dbrgn avatar dbrgn commented on June 13, 2024

It would probably help if you'd post your code.

from a2.

rajesh-blueshift avatar rajesh-blueshift commented on June 13, 2024

Here is the code:

use a2::{Client, Endpoint, NotificationBuilder, NotificationOptions, PlainNotificationBuilder};
use argparse::{ArgumentParser, Store, StoreOption, StoreTrue};
use pretty_env_logger;
use std::fs::File;
use tokio;

// An example client connectiong to APNs with a certificate and key
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    pretty_env_logger::init();

    let mut certificate_file = String::from("/Users/rajesh/Downloads/BlueshiftPushBluePkcs.p12");
    let mut password = String::from("blueshift");
    let mut device_token = String::from("860177d09c9a45900a20b1bf5de4eeddd4046b151bb837523d3218fdb135ead2");
    let mut message = String::from("Ch-check it out!");
    let mut sandbox = true;
    let mut topic: Option<String> = Some(String::from("com.blueshift.reads"));


    // Read the private key and certificate from the disk
    let mut certificate = File::open(certificate_file).unwrap();

    // Which service to call, test or production?
    let endpoint = if sandbox {
        Endpoint::Sandbox
    } else {
        Endpoint::Production
    };

    // Connecting to APNs using a client certificate
    let client = Client::certificate(&mut certificate, &password, endpoint).unwrap();

    let options = NotificationOptions {
        apns_topic: topic.as_ref().map(|s| &**s),
        ..Default::default()
    };

    // Notification payload
    let mut builder = PlainNotificationBuilder::new(message.as_ref());
    builder.set_sound("default");
    builder.set_badge(1u32);

    let payload = builder.build(device_token.as_ref(), options);
    println!("Sending payload");

    
    let response = client.send(payload).await?;

    println!("Sent: {:?}", response);

    Ok(())
}

from a2.

franklinvv avatar franklinvv commented on June 13, 2024

Using the example code on macOS to send a notification with token based authentication, I am getting the exact same error. I am trying with a2 v0.6.0 and have added tokio v1.5.0 as dependency. I am new to Rust as well.

The backtrace ends with the following:

    39: tokio::runtime::Runtime::block_on
         at /Users/franklin/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.5.0/src/runtime/mod.rs:452:43
    40: notifier::main
         at /Users/franklin/Developer/rust/Notifier/src/main.rs:9:1
    41: core::ops::function::FnOnce::call_once
         at /Users/franklin/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5

If I use a2 v0.5.3 and add tokio v0.2.25 as dependency, everything works fine.

from a2.

franklinvv avatar franklinvv commented on June 13, 2024

Apparently, this is solved by enabling the runtime feature of the hyper dependency.

from a2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.