PromiseKit icon indicating copy to clipboard operation
PromiseKit copied to clipboard

iOS 26 will remove ALAssetsLibrary. When do you expect to provide a compatible version?

Open LaoMaRen opened this issue 6 months ago • 3 comments

public func promise(_ vc: UIImagePickerController, animated: Bool = false, completion: (() -> Void)? = nil) -> Promise<NSData> {
    let proxy = UIImagePickerControllerProxy()
    vc.delegate = proxy

    present(vc, animated: animated, completion: completion)

    return proxy.promise.then(on: nil) { info -> Promise<NSData> in
    #if swift(>=4.2)
        let url = info[.referenceURL] as! URL
    #else
        let url = info[UIImagePickerControllerReferenceURL] as! URL
    #endif
        
        return Promise { seal in
            ALAssetsLibrary().asset(for: url, resultBlock: { asset in
                let N = Int(asset!.defaultRepresentation().size())
                let bytes = UnsafeMutablePointer<UInt8>.allocate(capacity: N)
                var error: NSError?
                asset!.defaultRepresentation().getBytes(bytes, fromOffset: 0, length: N, error: &error)

                if let error = error {
                    seal.reject(error)
                } else {
                    seal.fulfill(NSData(bytesNoCopy: bytes, length: N))
                }
            }, failureBlock: { seal.reject($0!) } )
        }
    }.ensure {
        self.dismiss(animated: animated, completion: nil)
    }
}

}

LaoMaRen avatar Aug 01 '25 08:08 LaoMaRen

I also encountered this problem.

kuangtao22 avatar Aug 16 '25 00:08 kuangtao22

Hello @LaoMaRen @kuangtao22 Can you please tell me, where did you find this function? Is it from the Extensions?

RomanPodymov avatar Aug 16 '25 09:08 RomanPodymov

@RomanPodymov path: Extensions/AssetsLibrary/Sources/ALAssetsLibrary+Promise.swift

LaoMaRen avatar Sep 01 '25 02:09 LaoMaRen