相关疑难解决方法(0)

在iOS应用中通过WhatsApp共享图像/文本

是否可以通过iOS应用程序中的Whatsapp共享图像,文本或任何您想要的内容?我在google上搜索,但我只发现了有关Android实现的结果.

提前致谢!

iphone ios

49
推荐指数
6
解决办法
8万
查看次数

使用 Whatsapp 发送图像和文本

我需要从我的应用程序发送带有文本的图像,我知道如何仅发送图像或仅发送文本,但我不知道如何将两者结合起来。

只是一张图片:

    let image = UIImage(named: "Image") // replace that with your UIImage

    let filename = "myimage.wai"
    let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, false)[0] as! NSString
    let destinationPath = documentsPath.stringByAppendingString("/" + filename).stringByExpandingTildeInPath
    UIImagePNGRepresentation(image).writeToFile(destinationPath, atomically: false)
    let fileUrl = NSURL(fileURLWithPath: destinationPath)! as NSURL

    documentController = UIDocumentInteractionController(URL: fileUrl)
    documentController.delegate = self
    documentController.UTI = "net.whatsapp.image"
    documentController.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: false)    
Run Code Online (Sandbox Code Playgroud)

只是一段文字:

    var whatsappURL = NSURL(string: "whatsapp://send?text=hello,%20world")

    if UIApplication.sharedApplication().canOpenURL(whatsappURL!) {
        UIApplication.sharedApplication().openURL(whatsappURL!)
    }    
Run Code Online (Sandbox Code Playgroud)

如何发送带有文本的图像?

编辑#1

我找到了一个代码,可以将带有文本的图像共享到whatsapp,但它是用java编写的,你能将它翻译成swift吗?

Intent whatsappIntent = new Intent(android.content.Intent.ACTION_SEND);
whatsappIntent.setType("image/*");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "Hello World");
whatsappIntent.putExtra(Intent.EXTRA_STREAM, …
Run Code Online (Sandbox Code Playgroud)

xcode ios whatsapp swift

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

ios ×2

iphone ×1

swift ×1

whatsapp ×1

xcode ×1