使用UIImage编写UIActivityTypeMessage [英] Compose UIActivityTypeMessage with UIImage

查看:192
本文介绍了使用UIImage编写UIActivityTypeMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人能提供一些见解,那就是徘徊。对于我的生活,我无法弄清楚如何使用UIActivityTypeMessage发送UIImage,尽管有人说这是可能的。

Was wandering if anyone can offer some insight. For the life of me I can't figure out how to send a UIImage with UIActivityTypeMessage all though some say it is possible.

文档说:
< a href =http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIActivity_Class/Reference/Reference.html =noreferrer> http://developer.apple.com/library /ios/#documentation/UIKit/Reference/UIActivity_Class/Reference/Reference.html

UIActivityTypeMessage

该对象将提供的内容发布到Messages应用程序。使用此服务时,可以提供NSString和NSAttributedString对象作为活动项的数据。您还可以指定其内容使用sms方案的NSURL对象。
适用于iOS 6.0及更高版本。
在UIActivity.h中声明。

The object posts the provided content to the Messages app. When using this service, you can provide NSString and NSAttributedString objects as data for the activity items. You may also specify NSURL objects whose contents use the sms scheme. Available in iOS 6.0 and later. Declared in UIActivity.h.

所以根据我的理解,我只能发送NSString / NSURL。我不认为你有可能。

So to my understanding I can only send NSString/NSURL. I don't see you it is possible.

我正在使用这个:

UIImage *image; // some image here.

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[ image ] applicationActivities:nil];

我们非常感谢任何帮助。

Any help would be much appreciated.

推荐答案

虽然似乎可以使用iOS6中的UIActivityViewController让消息应用程序出现在共享表中,但是有一些秘密可以使它工作 - iOS7是一个不同的故事,通过资产的NSURL开箱即用。

While it seems possible to get the message app to appear in the share sheet using UIActivityViewController in iOS6, there is some secret to get it to work--iOS7 is a different story, passing the NSURL to the asset works out of the box.

不确定是从ALAssetsLibrary获取图像,但如果是这样,请使用其NSURL获取ALAsset而不是拉动UIImage的。共享表在很短的时间内出现。这不是我正在使用的代码,但类似。但是在iOS6上,只要附加了图像,活动视图控制器就不会显示消息应用程序。

Not sure you are getting your images from the ALAssetsLibrary, but if so, grab the ALAsset using its NSURL rather than pulling the UIImage. The share sheet appears in a fraction of the time. This isn't exactly the code I'm using, but similar. But on iOS6, the activity view controller will not show the messages app so long as there is an image attached.

- (void) presentActivityViewController:(ALAsset*) asset {
    // add this to your viewController class

    NSDictionary *urls = [asset valueForProperty:ALAssetPropertyURLs];
    NSURL *url;
    if ([urls count]) {
        for (NSString *key in urls) {
            // I'm making an assumption that the URL I want is the first URL in the dictionary
            url = [urls objectForKey:key];
            break;
        }
    }

    NSArray *activityItems = @[url];
    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    [self presentViewController:activityController animated:YES completion:nil];
}

这篇关于使用UIImage编写UIActivityTypeMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆