Wie erhalte ich die URL eines Bildes, das gerade in PHPhotoLibrary hinzugefügt wurde?

Ich benutze den UIImagePickerController in zwei Fällen

, um ein vorhandenes Bild in der Fotobibliothek auszuwählenum ein neues Bild zu machen

Im ersten Fall, wenn ich ein Bild aus der Bibliothek auswähle, kann ich die URL einfach in der Delegate-Methode abrufen:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Get the URL
    NSURL *url = [info valueForKey:UIImagePickerControllerReferenceURL];
    ...
}

Aber wenn ich ein neues Bild mache, ist das Bild noch nicht in der Fotobibliothek und hat noch keine URL. Also muss ich zuerst das Bild in die Bibliothek einfügen. Aber wie erhält man dann die URL des neuen Assets?

Hier ist mein Code zum Hinzufügen des Bildes in die Fotobibliothek

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Get the image
    UIImage *image = [info objectF,orKey:UIImagePickerControllerOriginalImage];

    // Add the image in the library
    [[PHPhotoLibrary sharedPhotoLibrary]

        performChanges:^
        {
            // Request creating an asset from the image.
            PHAssetChangeRequest *createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];

            // Get the URL of the new asset here ?
            ...
        }

        completionHandler:^(BOOL success, NSError *error)
        {
            if (!success) { ...; return; }

            // Get the URL of the new asset here ?
            ...
        }
    ];
}

Antworten auf die Frage(12)

Ihre Antwort auf die Frage