1

Estoy haciendo una app, que es un lector de rss.

Lo que quiero es que se pueda compartir una noticia por whatsapp, y que los datos que se compartan sean:

  • Una imagen
  • Un titulo
  • Un enlace

De momento tengo esto:

let urlString = "Hello Friends, Sharing some data here..."
        let urlStringEncoded = urlString.stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
        //URLHostAllowedCharacterSet
        urlToGo  = NSURL(string: "whatsapp://send?text=\(urlStringEncoded!)")
        print(urlToGo)
        if UIApplication.sharedApplication().canOpenURL(urlToGo!){
            UIApplication.sharedApplication().openURL(urlToGo!)
        }else{
            let alertController = UIAlertController(title: "Error", message: "No tienes instalado Whatsapp en el dispositivo", preferredStyle: .Alert)

            let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)

            alertController.addAction(defaultAction)
            presentViewController(alertController, animated: true, completion: nil)

        }

Como puedo hacer para añadir un enlace, un texto y una imagen?

Hay alguna libreria con la que lo pueda realizar

Gracias!!!!

1 respuesta 1

0

Puedes usar UIActivityViewController para compartir la imagen, el texto y el enlace.

NSString *textToShare = @"Enter your text to be shared";
UIImage * image = [UIImage imageNamed:@"imagename"];

NSArray *objectsToShare = @[textToShare, image];

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];


[self presentViewController:activityVC animated:YES completion:nil];

Alguien preguntó lo mismo en stackoverflow en inglés: (https://stackoverflow.com/a/35745644/4955542)

@AlbertoMier Pregunté en la ruta precedente, si podía servir el código para Swift 2 y me han respondido con esta parte de código por si lo quieres probar.

let shareText = "Hello, world!" if let image = UIImage(named: "myImage") { let vc = UIActivityViewController(activityItems: [shareText, image], applicationActivities: []) presentViewController(vc, animated: true, completion: nil) }

Te dejo un enlace de una app hecha en swift que dice que hace eso que quieres. La app la han actualizado hace 2 días seguro que te sirve para swift 2. (https://github.com/LauraSempere/meme-app)

4
  • ¿No te sirve @AlbertoMier? el 5 jul. 2016 a las 5:41
  • Yo lo necesito en swift 2 @MarcLemien
    – user9099
    el 7 jul. 2016 a las 11:04
  • He actualizado mi respuesta @AlbertoMier el 7 jul. 2016 a las 21:14
  • Muchas gracias, lo probare @MarcLemien
    – user9099
    el 8 jul. 2016 a las 4:57

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.