Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 操作扩展,在即时标记中获取图像将返回一个空白屏幕_Ios_Swift - Fatal编程技术网

Ios 操作扩展,在即时标记中获取图像将返回一个空白屏幕

Ios 操作扩展,在即时标记中获取图像将返回一个空白屏幕,ios,swift,Ios,Swift,背景 我有一个可用于图像的操作扩展: 类ActionViewController:UIViewController{ @IBVAR imageView:UIImageView! 重写func viewDidLoad(){ super.viewDidLoad() var imageFound=false 对于self.extensionContext!.inputItems as![NSExtensionItem]中的项目{ 对于item.attachments中的提供程序{ if provide

背景 我有一个可用于图像的操作扩展:

类ActionViewController:UIViewController{
@IBVAR imageView:UIImageView!
重写func viewDidLoad(){
super.viewDidLoad()
var imageFound=false
对于self.extensionContext!.inputItems as![NSExtensionItem]中的项目{
对于item.attachments中的提供程序{
if provider.hasItemConformingToTypeIdentifier(kUTTypeImage作为字符串){
弱var weakImageView=self.imageView
loadItem(forTypeIdentifier:kUTTypeImage作为字符串,选项:nil,completionHandler:{(imageURL,错误)位于
OperationQueue.main.addOperation{
如果让strongImageView=weakImageView{
如果让imageURL=imageURL作为?URL{
strongImageView.image=UIImage(数据:try!数据(内容:imageURL))
}
}
}
})
imageFound=true
打破
}
}
如果(找到图像){
打破
}
}
}
上述代码是创建操作扩展时的默认代码。如果我在
照片
应用程序>选择图像>共享>我的操作扩展,则上述代码将正确执行。然后,图像将显示在我的操作扩展中的UIImageView中。但是,当我拍摄屏幕截图并按下共享按钮时,(例如,请参见下图),使用my Action Extension共享图像会返回一个空白屏幕,控制台中不会出现错误。其他应用程序也会出现类似情况。我注意到,可以通过即时标记工具进行共享,因为我可以与Gmail共享图像

以下是我的Info.plist:

NSExtensionActivationRule
子查询(
伸展岩,
多边主义,
子查询(
$m.attachments,
$附件,
任何$attachment.registeredTypeIdentifiers UTI-Compliance-TO“public.item”||
任何$attachment.registeredTypeIdentifiers UTI-Compliance-TO“public.content”
)@count=$extensionItem.attachments@count
)@count>0

问题:我不完全确定如何从即时标记工具(内置iOS屏幕截图工具)获取图像。

我通过以下链接找到了答案:

问题出在哪里?

问题是,当您从照片加载图像时,图像类型为URL,而从截图工具加载图像时,图像类型为UIImage。因此,有必要针对不同的情况显式处理数据加载

我就是这样实施的:

如果让content=extensionContext!.inputItems[0]作为?NSExtensionItem{
将contentType=kUTTypeImage设为字符串
if(content.attachments)!=nil{
用于content.attachments中的附件{
if attachment.hasItemConformingToTypeIdentifier(内容类型为字符串){
loadItem(forTypeIdentifier:contentType作为字符串,选项:nil){data,中有错误
如果错误==nil{
var contentData:数据?=nil
//处理图像数据是否为原始数据。
如果让数据=数据为?数据{
contentData=data
//处理图像数据是否为URL。
}否则,如果让url=数据作为?url{
contentData=try?数据(contentsOf:url)
}
//处理图像数据是否为UIImage对象,例如来自屏幕截图工具。
否则,如果让imageData=数据为UIImage{
contentData=imageData.pngData()
}
//继续这里的contentData。
self.imageView.image=UIImage(数据:contentData!)
}
}
}
}
}
}
完成T,O,D,O 8.0 0 0 0 8 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 0 0 0 0 0 8 8 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 0 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0,r r r,r r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,rγγγγγ,r,r,以及其他其他其他其他,r,rγγγγγγγγγγ,γγγ,对对对该该该方方方方,以及以及以及其他其他其他其他其他其他其他其他的,γαααααααα,我,我,我,我,我,我方,我方,我方,我方,我方,我本本本本本本本本本省省省省省省省省省省省省,我,我,我,我,我8.0奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈奈8.Cγ-8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 h,o,w,e,v,e,r,t,h,i,s,i,s7.7 7 7.8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7.2,我要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是要是本本本该该该该该该该该该该该该方的研究,那么那么那么那么那么那么那么那么那么那么能能能能能用用用用用用用用用用用用本本本本本本本研究的话,本本研究的开展开展开展开展开展开展开展开展开展开展开展的话,本本本研究,本研究,本研究,本在本研究中,克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克克洛斯-克洛斯-克洛斯-克克洛斯-克洛斯-克洛斯-克克洛斯-克克洛斯-克洛斯-克洛斯-克克洛斯-克克克洛斯-克洛斯-克克洛斯-克洛斯-克洛斯-克克洛斯-克洛斯-克洛斯-克克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克克洛斯-克洛斯-克洛斯-克洛斯-克洛斯-克克克克洛斯-克洛斯-克洛斯-克洛;o̶l̶u̶t̶i̶o̶n̶t̶o̶t̶h̶在本研究中,除除其他外,还有其他外,其他的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市的城市a,s,a,c,o,m,m,e,n,t

延迟可以通过将图像加载到不同的线程来解决(据我所知):

var imageFound=false
对于self.extensionContext!.inputItems as![NSExtensionItem]中的项目{
对于item.attachments中的提供程序{
if provider.hasItemConformingToTypeIdentifier(kUTTypeData作为字符串){
弱var weakImageView=self.imageView
loadItem(forTypeIdentifier:kUTTypeData作为字符串,选项:nil,completionHandler:{(数据,错误)在
DispatchQueue.main.async{
如果让strongImageView=weakImageView{
var contentData:数据?=nil
//处理图像数据是否为原始数据