简体   繁体   English

SwiftUI | 如何使用共享表复制本地化字符串?

[英]SwiftUI | How to use share sheet to copy localized strings?

I added share sheet button and it works great for my English texts (copying,sharing) BUT for the localized texts the app hung and crash when I add LocalizedStringKeys() , and when I don't add it the text is showing English.我添加了共享表按钮,它对我的英文文本(复制、共享)非常有用,但对于本地化文本,当我添加LocalizedStringKeys()时应用程序挂起并崩溃,当我不添加它时,文本显示为英文。

 func shareSheet(){
    isShareSheetShowing.toggle()
    let av = UIActivityViewController(activityItems: [LocalizedStringKey(quote)], applicationActivities: nil)
    UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)

}

You can use directly NSLocalizedString可以直接使用NSLocalizedString

func shareSheet(){
   isShareSheetShowing.toggle()
   let av = UIActivityViewController(activityItems: [NSLocalizedString(quote, comment: "")], applicationActivities: nil) //<--Here
   UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM