我还没有找到自己喜欢的机制,因此值得一试。麻烦的部分原因是更高版本的iOS增加了应用程序添加系统范围的“共享和操作扩展”的功能。这些第三方项目似乎以各种方式编码。有些继承了应用程序的导航栏样式,有些使用了自己的导航栏样式,有些似乎采用了白色导航栏(但实际上是继承自应用程序)。
这已在iOS 12.2上进行了测试。
我创建了一个UIActivityItemSource
,我有:
- (nullable id)activityViewController:(nonnull UIActivityViewController *)activityViewController itemForActivityType:(nullable UIActivityType)activityType {
if (activityType == UIActivityTypePrint || [activityType.lowercaseString containsString:@"extension"] || [activityType containsString:@"AssignToContact"]) {
//What a hack, but the best I can do. Seems some extensions inherit nav style from parent, others don't.
//ActionExtension is bottom row; all those I tested need this. The string comparison catches most non-OS extensions (the type is set by developer).
[[UINavigationBar appearance] setBarTintColor:[UIColor kNavigationBarBackgroundColor]]; //kNavigationBarBackgroundColor is my app's custom nav bar background color
} else {
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
}
return self.pdfData; //In my case I'm sharing a PDF as NSData - modify as needed for your shared item
}
然后在我UIActivityViewController
的中completionWithItemsHandler
,包括:
[[UINavigationBar appearance] setBarTintColor:[UIColor kNavigationBarBackgroundColor]]; //Again, this is my app's custom nav bar background color
与特定问题无关,但是如果您当前没有UIActivityItemSource
,则需要执行以下操作:
NSArray *activities=@[self]; //And set self to be a UIActivityItemSource
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:activities applicationActivities:nil];
我确定这不是100%可靠,但可以与我尝试过的所有扩展一起使用。