IOS/Objective-C:UIActivityItemSource 协议,用于自定义与 UIActivityViewController 的共享消息
IOS/Objective-C: UIActivityItemSource Protocol for customizing share messages with UIActivityViewController
Apple 文档说您可以使用 UIActivityItemSource
协议来自定义与 UIActivityViewController
共享的消息,以代替 UIActivityItemProvider
对象:
UIActivityItemSource
You can use this protocol in situations where you want to provide the data from one of your app’s existing objects instead of creating a separate UIActivityItemProvider object.
我已经采用了这个协议,但是,如下所示的委托方法似乎没有触发。任何人都可以确认这应该有效,如果是这样,请指出我可能缺少的东西?提前感谢您的任何建议。
-(NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(UIActivityType)activityType
{
NSLog(@"DELEGATE METHOD CALLED");//Not logging to console
if (activityType == UIActivityTypeMessage) {
return @"My message";
} else if (activityType == UIActivityTypeMail) {
return @"My email text";
}
else {
return @"My default text";
}
}
是的,这个委托方法对我有用,调用了委托方法。我使用以下代码创建 activity 项目控制器:
NSArray *theItems = @[ self ];
UIActivityViewController *theController = [[UIActivityViewController alloc] initWithActivityItems:theItems applicationActivities:nil];
theController.popoverPresentationController.barButtonItem = self.shareButton;
theController.excludedActivityTypes = @[ UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo, UIActivityTypeAirDrop ];
[self presentViewController:theController animated:YES completion:NULL];
其中 self
实现 UIActivityItemSource
.
Apple 文档说您可以使用 UIActivityItemSource
协议来自定义与 UIActivityViewController
共享的消息,以代替 UIActivityItemProvider
对象:
UIActivityItemSource
You can use this protocol in situations where you want to provide the data from one of your app’s existing objects instead of creating a separate UIActivityItemProvider object.
我已经采用了这个协议,但是,如下所示的委托方法似乎没有触发。任何人都可以确认这应该有效,如果是这样,请指出我可能缺少的东西?提前感谢您的任何建议。
-(NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(UIActivityType)activityType
{
NSLog(@"DELEGATE METHOD CALLED");//Not logging to console
if (activityType == UIActivityTypeMessage) {
return @"My message";
} else if (activityType == UIActivityTypeMail) {
return @"My email text";
}
else {
return @"My default text";
}
}
是的,这个委托方法对我有用,调用了委托方法。我使用以下代码创建 activity 项目控制器:
NSArray *theItems = @[ self ];
UIActivityViewController *theController = [[UIActivityViewController alloc] initWithActivityItems:theItems applicationActivities:nil];
theController.popoverPresentationController.barButtonItem = self.shareButton;
theController.excludedActivityTypes = @[ UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo, UIActivityTypeAirDrop ];
[self presentViewController:theController animated:YES completion:NULL];
其中 self
实现 UIActivityItemSource
.