UIActivityViewController和Notes

时间:2015-10-01 02:14:44

标签: ios uiactivityviewcontroller

我的应用程序中有UIActivityViewController用于发布到Facebook,但它也添加了Notes作为选项,但由于Notes没有UIActivityType,我不能排除它,但它也没有添加任何内容。我的代码是:

Mail *mail = [[Mail alloc]init];
    NSString *html = self.finalObject[@"Request"];
    NSString *thetitle = [self.finalObject[@"Title"] stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSString *thedate = self.finalObject[@"dateMade"];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MMM_dd_yyyy"];
    [dateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
    NSDate *theNewDate1 = [dateFormat dateFromString:thedate];
    NSString *theNewDate = [dateFormat stringFromDate:theNewDate1];

    mail.thehtml = html;
    self.nameofhtmlfile = [[[[@"http://www.iprayed4u.net/app/" stringByAppendingString:thetitle] stringByAppendingString:@"_"] stringByAppendingString:theNewDate] stringByAppendingString:@".html"];

    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[self] applicationActivities:@[mail]];



        activityVC.excludedActivityTypes = @[ UIActivityTypePostToWeibo,

                                              UIActivityTypeCopyToPasteboard,

                                              UIActivityTypeAssignToContact,
                                              UIActivityTypeMail,
                                              UIActivityTypePrint,
                                              UIActivityTypeAirDrop
                                              ];



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

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {

    if ([activityType isEqualToString:UIActivityTypePostToTwitter]){
        NSString *test = [[@"I just pledged to pray.  You can pray too, just click " stringByAppendingString:self.nameofhtmlfile] stringByAppendingString:@" to view request.  Get #iPrayed4U here https://appsto.re/us/p_t30.i"];
        return test;
    }
    if ([activityType isEqualToString:UIActivityTypePostToFacebook]){
        NSString *test = [[[[[@"'" stringByAppendingString:self.finalObject[@"Title"]] stringByAppendingString:@"'.  "] stringByAppendingString:@"I just pledged to pray.  You can pray too, just click " ] stringByAppendingString:self.nameofhtmlfile] stringByAppendingString:@" to view request.  You can also get the app for free.  Check out iPrayed 4 U on iOS at https://appsto.re/us/p_t30.i #iPrayed4U"];
        return test;
    }
    if ([activityType isEqualToString:UIActivityTypeMessage]){
        NSString *test = [[[[[@"'" stringByAppendingString:self.finalObject[@"Title"]] stringByAppendingString:@"'.  "] stringByAppendingString:@"I just pledged to pray.  You can pray too, just click " ] stringByAppendingString:self.nameofhtmlfile] stringByAppendingString:@" to view request.  You can also get the app for free.  Check out iPrayed 4 U on iOS at https://appsto.re/us/p_t30.i #iPrayed4U"];
        return test;
    }
    return nil;
}
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
    return @"Some string";
}

如何从UIActivityViewController中删除Notes,或者让它实际运行?

1 个答案:

答案 0 :(得分:4)

您不能排除Notes,因为它不是系统活动:它是共享扩展。只有用户可以决定是包含它还是将其排除。

现在您已经添加了其余的代码,您可以看到Notes为什么不保存任何内容:您没有处理任何数据。当Notes要求输入数据时,您将返回nil

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
    if ([activityType isEqualToString:UIActivityTypePostToTwitter]){
    }
    if ([activityType isEqualToString:UIActivityTypePostToFacebook]){
    }
    if ([activityType isEqualToString:UIActivityTypeMessage]){
    }
    return nil; // this is what you are sending to Notes
}