我使用UIActivityViewController来显示共享。在我选择邮件应用程序的列表中,主题和正文设置正确,Gmail应用程序中的位置为空。
- (void)shareAVideoWithSubject:(NSString*)subject Link:(NSString *)string onViewController:(UIViewController *)viewController fromView:(UIView *)view {
_activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:@[string]
applicationActivities:nil];
_activityViewController.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypeAirDrop];
[_activityViewController setValue:subject forKey:@"subject"];
UIWindow *window = [[[UIApplication sharedApplication] delegate]window];
//if iPhone
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if(!viewController){
viewController = ((SWRevealViewController*)window.rootViewController).presentedViewController;
}
[viewController presentViewController:_activityViewController
animated:YES
completion:nil];
}
//if iPad
else
{
// Change Rect to position Popover
popup = [[UIPopoverController alloc] initWithContentViewController:_activityViewController];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:view];
[popup presentPopoverFromBarButtonItem:barButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
我在StackOverFlow上检查了以下两个问题。
这些不是我的问题的答案,因为他们在列表中添加新活动,而我希望iOS显示所有可共享的应用程序。在这种情况下,Gmail共享正在变空。
提前致谢。 添加截图,
答案 0 :(得分:12)
[_activityViewController setValue:subject forKey:@"subject"];
没有记录设置电子邮件主题的方式。
设置正文和主题的正确方法(iOS 7.0及更高版本) - 在要共享的项目上实施UIActivityItemSource
协议。
// EmailItemProvider.h
@interface EmailItemProvider : NSObject <UIActivityItemSource>
@property (nonatomic, strong) NSString *subject;
@property (nonatomic, strong) NSString *body;
@end
// EmailItemProvider.m
#import "EmailItemProvider.h"
@implementation EmailItemProvider
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return _body;
}
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
return _body;
}
- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType {
return _subject;
}
@end
而不是呈现它:
EmailItemProvider *emailItem = [EmailItemProvider new];
emailItem.subject = @"Subject";
emailItem.body = @"Body";
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:@[emailItem]
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
这将在邮件应用上设置正文和主题,但似乎Gmail应用忽略主题并将其设置为正文。
重要:好像Gmail应用中存在错误。传递&
个字符会使邮件主题和正文变为空。请改用&
。其他特殊字符未经过测试。
答案 1 :(得分:0)
对于Swift(4)恋人:
activityViewController(_:subjectForActivityType:)允许我们将主题设为共享方法。
struck stackelementS {
void* contents;
struct stackelementS* next;
}
typedef struct stackelementS stackelement;
struct stackS {
stackelement* top;
}
typedef struct stackS* stack;
答案 2 :(得分:-2)
UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@ [@&#34;你的身体字符串要分享&#34;] applicationActivities:无];
[activityViewController setValue:@&#34;您的电子邮件主题&#34; forKey:@&#34受试者#34;];
activityViewController.completionHandler = ^(NSString * activityType,BOOL completed){ // ... };