使用UIActivityController在facebook和twitter之间共享不同的字符串

时间:2014-07-10 17:26:18

标签: ios objective-c facebook twitter uiactivityviewcontroller

我目前正在构建一个UIActivityController来分享邮件,邮件,Twitter和Facebook的帖子我目前有这个代码

NSString *textToShare = string3;
UIImage *imageToShare = [UIImage imageNamed:@"INFO.png"];
NSArray *itemsToShare = @[textToShare, imageToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:YES completion:nil];

除了Twitter仅允许一定数量的角色之外,这是完美的。我有办法裁剪我的帖子,以便它适合twitter:

    NSString *shorturl = @"http://vimeo.com/";
    NSString* title = @"LOREM IPSUM lorem ipsum LOREM IPSUM lorem ipsum LOREM IPSUM lorem ipsum LOREM IPSUM lorem ipsum LOREM IPSUM lorem ipsum";
    NSString *part1 = [title stringByAppendingString: @" "];

    NSString *hashtag = [@"#" stringByAppendingString: _genret];

    NSString *lengthcheck = [part1 stringByAppendingString: hashtag];
    NSUInteger lenthtotes = [lengthcheck length];
    NSUInteger req = 77;

    NSUInteger lenthhash = 72 -[hashtag length];
    if(lenthtotes > req){
        NSString* tites = [title substringWithRange:NSMakeRange(0, lenthhash)];
        title = [tites stringByAppendingString: @"..."];
        part1 = [title stringByAppendingString: @" "];
    }


    NSString* part2 = [part1 stringByAppendingString: hashtag];


    NSString *part3 = [part2 stringByAppendingString: @" "];

    NSString *string3 = [part3 stringByAppendingString: shorturl];

    NSLog(string3);

哪个庄稼的标题是三个" ..."如果它长于给定的长度。

但是我希望能够将未剪切的帖子用于其他三个帖子。这可能吗?

0 个答案:

没有答案