gpt4 book ai didi

ios - 如何使用静态函数通过完成处理程序调用 UIImageWriteToSavedPhotosAlbum()?

转载 作者:可可西里 更新时间:2023-11-01 01:36:56 27 4
gpt4 key购买 nike

我可以调用 UIImageWriteToSavedPhotosAlbum 并毫无问题地处理完成:

class A {
func saveNow() {
UIImageWriteToSavedPhotosAlbum(someImage, self, "saveImage:didFinishSavingWithError:contextInfo:", nil)
}

func saveImage(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
// handle completion
}
}

但是,如果我想让 saveNow() 成为静态函数,我就无法正确设置 completionTargetcompletionSelector我可以处理完成:

class B {
static func saveNow() {
UIImageWriteToSavedPhotosAlbum(someImage, /* how to set here */)
}

static func saveImage completionSelector(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
}
}

如果要使用静态函数,如何修改类B?

最佳答案

您需要做的是将目标设置为 YourClassName.self

即,

UIImageWriteToSavedPhotosAlbum(someImage, YourClassName.self, "saveImage:didFinishSavingWithError:contextInfo:", nil)

顺便说一句,你的函数名不正确:

//Note the space between saveImage and completionSelector
static func saveImage completionSelector(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>)

我认为应该是:

static func saveImageWithCompletionSelector(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) 

因此,我们可能需要做相应的改变:

UIImageWriteToSavedPhotosAlbum(someImage, YourClassName.self, "saveImageWithCompletionSelector:didFinishSavingWithError:contextInfo:", nil)

我刚刚根据上述更改和建议进行了快速测试;应该有一个弹出窗口请求授权访问相册。

关于ios - 如何使用静态函数通过完成处理程序调用 UIImageWriteToSavedPhotosAlbum()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36109466/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com