简体   繁体   English

iOS社交框架和图片发布

[英]IOS Social framework and image post

I am experimenting with the Social Framework. 我正在尝试使用社交框架。 I was wondering if there is any possible way to attach the last photo taken and currently saved in the camera roll using this implementation from my app: 我想知道是否有任何可能的方法,可以使用我的应用中的此实现来附加上次拍摄并当前保存在相机胶卷中的照片:

 - (IBAction)shareByActivity:(id)sender {
    NSArray *activityItems;

    if (self.sharingImage != nil) {
        activityItems = @[self.sharingImage, self.sharingText, self.addURL];
    } else {
        activityItems = @[self.sharingText, self.addURL];
    }

    UIActivityViewController *activityController =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                      applicationActivities:nil];

    [self presentViewController:activityController
                       animated:YES completion:nil];
}

If so how do I modify the shareImage name in this specific portion of my -(void)viewDidLoad ? 如果是这样,如何在-(void)viewDidLoad此特定部分中修改shareImage名称?

self.sharingImage = [UIImage imageNamed:@"notSureWhatToPutHere"];

Everything works well, the social panel opens and has all the needed service. 一切正常,社交面板打开并提供所有需要的服务。 My only request is to find out how to call the latest image from the camera roll. 我唯一的要求是找出如何从相机胶卷中调用最新图像。 I am not sure if I need the image real name or if there is any other way to achieve what i would like: a post with a picture attached (most recent picture in camera roll). 我不确定我是否需要图像的真实姓名,或者是否有其他方法可以实现我想要的效果:贴有图片的帖子(相机胶卷中的最新图片)。

Any help is appreciated. 任何帮助表示赞赏。

You can pretty painlessly get the last image in the camera roll using the asset library framework. 您可以使用资产库框架轻松地获得相机胶卷中的最后一张图像。 Give this a try: 试试看:

#import <AssetsLibrary/AssetsLibrary.h>

Then to get the image: 然后获得图像:

ALAssetsLibrary *cameraRoll = [[ALAssetsLibrary alloc] init];
[cameraRoll enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *images, BOOL *stop) {
    [images setAssetsFilter:[ALAssetsFilter allPhotos]];
    [images enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:[images numberOfAssets] - 1] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){
        if (result) {
            ALAssetRepresentation *rep = [result defaultRepresentation];
            self.sharingImage = [UIImage imageWithCGImage:[rep fullScreenImage]];
        }
    }];


}
                        failureBlock: ^(NSError *error) {
                            NSLog(@"An error occured: %@",error);
                        }];

Thanks for the great help NSPostWhenIdle! 感谢NSPostWhenIdle的大力帮助!

I was able to resolve the issue of getting "newest photos" from camera roll by moving my ALAssettsLibrary chuck of code away from viewDidLoad and created a refreshAlbum 通过将我的ALAssettsLibrary代码夹从viewDidLoad移开,我能够解决从相机胶卷获取“最新照片”的问题,并创建了refreshAlbum

 - (void) refreshAlbum
{
ALAssetsLibrary *cameraRoll = [[ALAssetsLibrary alloc] init];
[cameraRoll enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *images, BOOL *stop) {
    [images setAssetsFilter:[ALAssetsFilter allPhotos]];
    [images enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:[images numberOfAssets] - 1] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
     {
         if (result) {

             ALAssetRepresentation *rep = [result defaultRepresentation];
             self.sharingImage = [UIImage imageWithCGImage:[rep fullScreenImage]];
         }
     }];
}
                        failureBlock: ^(NSError *error) {
                            NSLog(@"An error occured: %@",error);
                        }];
}

Then I am calling the newly created refreshAlbum from the same button that enable the shareByActivity 然后,我从启用了shareByActivity的同一按钮调用新创建的refreshAlbum

- (IBAction)refreshButton:(id)sender {
    [self refreshAlbum];
}

This work particularly well as my app does not have any picture to share as it starts up. 由于我的应用程序启动时没有任何图片可共享,因此效果特别好。 The first time that imageShare become available is after activating the shareByActivity button that now carries the refreshButton function as well! imageShare首次可用是在激活shareByActivity按钮之后,该按钮现在也带有refreshButton功能!

Thanks again, this really work. 再次感谢,这确实有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM