IvanJiang123
IvanJiang123
  • 发布:2023-04-04 14:56
  • 更新:2023-04-04 15:03
  • 阅读:476

为什么UTS中调用UIActivityViewController闪退?

分类:uts

调用UIActivityViewController直接闪退

import { UIActivityViewController } from 'UIKit'  
import { NSExtensionItem, NSItemProvider } from 'Foundation'  
import { UTSiOS } from "DCloudUTSFoundation"  
export default function fpsPay(t : boolean = false) {  
    let item = new NSExtensionItem()  
    let attachment = new NSItemProvider(item = null, typeIdentifier = "hk.com.hkicl")  
    item.attachments = [attachment]  
    let activityViewController = new UIActivityViewController(activityItems = [item], applicationActivities = null)  
    UTSiOS.getCurrentViewController().present(activityViewController, animated = true, completion = null)  

}
2023-04-04 14:56 负责人:DCloud_iOS_XHY 分享
已邀请:
DCloud_iOS_LZY

DCloud_iOS_LZY

uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行

    DispatchQueue.main.async(execute = () : void => {  
        let item = new NSExtensionItem()    
        let attachment = new NSItemProvider(item = null, typeIdentifier = "hk.com.hkicl")    
        item.attachments = [attachment]    
        let activityViewController = new UIActivityViewController(activityItems = [item], applicationActivities = null)    
        UTSiOS.getCurrentViewController().present(activityViewController, animated = true, completion = null)    
    })

要回复问题请先登录注册