我的项目中有类似的代码,我在共享项之间获得冗余空间.是否可以删除它?
let text = "Some text\n" let link = NSURL(string: "https://stackoverflow.com/")! let items = [text,link] let activityVC = UIActivityViewController(activityItems: items,applicationActivities: nil) self.presentViewController(activityVC,animated: true,completion: nil)
解决方法
按照以下代码使用NSString代替NSURL:
NSString *text = @"Some Text"; NSString *URL = @"\nhttp://www.apple.com"; UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[text,URL] applicationActivities:nil]; [self presentViewController:controller animated:YES completion:nil];
——————- Swift代码(根据问题)————-
let text = "Some text" let link = "\nhttps://stackoverflow.com/" let items = [text,completion: nil)
您可以看到所附的屏幕截图.一旦您发布/发送消息,它仍将显示为链接.
如果URL不是activity items数组中的第一个对象,则URL将默认添加一个空格.
希望这可以帮助.