ich ein seltsames Verhalten erlebt habe:Lade Bild aus der Galerie durch lokale URL (Swift)
Ein imagePicker gibt einen PHAsset, und ich das Folgende und verwalten einen Imageview mit Bild aus den Daten zu präsentieren:
asset.requestContentEditingInput(with: PHContentEditingInputRequestOptions()) { (input, _) in
let url = input?.fullSizeImageURL
let imgV = UIImageView()
let test_url = URL(string: (url?.absoluteString)!)
print("><><><^^^><><>\(test_url)")
//prints: ><><><^^^><><>Optional(file:///var/mobile/Media/DCIM/107APPLE/IMG_7242.JPG)
let data = NSData(contentsOf: test_url! as URL)
imgV.image = UIImage(data: data! as Data)
imgV.backgroundColor = UIColor.cyan
att.imageLocalURL = url?.absoluteString//// saving the string to use in the other class
imgV.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
self.view.addSubview(imgV) /// just to test that the file exists and can produce an image
Allerdings, wenn ich die folgend in einer anderen Klasse:
if((NSURL(string: self.attachment.imageLocalURL!) as URL!).isFileURL)// checking if is Local URL
{
let test_url = URL(string: self.attachment.imageLocalURL!) // reading the value stored from before
print("><><><^^^><><>\(test_url)")
//prints :><><><^^^><><>Optional(file:///var/mobile/Media/DCIM/107APPLE/IMG_7242.JPG)
let data = NSData(contentsOf: test_url! as URL)
imageView.image = UIImage(data: data! as Data)
}
die Daten sind gleich Null! Was mache ich falsch, der String für URL ist in beiden Fällen identisch!
Haben Sie mit Haltepunkten versuchen und Schritt-für-Schritt sehen, wo es ein unerwartetes Ergebnis hervorbringt? – d00dle
Klasse A: url_a -> string_a -> Daten -> Bild, aber Klasse B: string_a -> Daten -> Null, das ist das unerwartete Verhalten. –