Die in der anderen Antwort angegebene UIActivityViewController macht dies trivial. Sie müssen lediglich den Text/das Bild/die URL angeben, die Sie freigeben möchten, und den Aktivitätsansicht-Controller modal darstellen, und iOS zeigt automatisch alle anwendbaren Freigabedienste an. Beispiele:
Objective-C
- (void)shareText:(NSString *)text andImage:(UIImage *)image andUrl:(URL *)url
{
NSMutableArray *sharingItems = [NSMutableArray new];
if (text) {
[sharingItems addObject:text];
}
if (image) {
[sharingItems addObject:image];
}
if (url) {
[sharingItems addObject:url];
}
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
}
Swift
func share(sharingText: String?, sharingImage: UIImage?, sharingURL: URL?) {
let sharingItems:[AnyObject?] = [
sharingText as AnyObject,
sharingImage as AnyObject,
sharingURL as AnyObject
]
let activityViewController = UIActivityViewController(activityItems: sharingItems.flatMap({$0}), applicationActivities: nil)
if UIDevice.current.userInterfaceIdiom == .pad {
activityViewController.popoverPresentationController?.sourceView = view
}
present(activityViewController, animated: true, completion: nil)
}
ich möchte share sheet mit benutzerdefinierten icon wie wechat, weibo, qq öffnen und integrieren die funktionalität davon, wie kann ich das tun? – RaviJSS
Überprüfen Sie einfach diesen Link auch .. http://Stackoverflow.com/a/35267035/3908884 –
[Hier ist ein einfaches Beispiel mit Swift] (http://StackOverflow.com/A/35931947) – Suragch