Es gibt eine Möglichkeit, das zu tun.
Objective C
Importieren der Fotos Rahmen
#import <Photos/Photos.h>
Dann wird Ihr Bild machen
UIImage * image = [UIImage imageNamed:@"DP.jpg"];
Dann speichern Sie das Bild. Das Bild wird unter Kamerarolle gespeichert.
Dies funktioniert gleich wie writeImageToSavedPhotosAlbum
von ALAssetsLibrary
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
[PHAssetChangeRequest creationRequestForAssetFromImage:image];
} completionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"Image Saved");
}
else {
NSLog(@"error in saving image : %@",error);
}
}];
Sicherstellen, dass die Erlaubnis für Fotos ist ON. Auch wenn Sie das Projekt von Xcode 8 erstellt haben, dann müssen Sie in Info.plist
<key>NSPhotoLibraryUsageDescription</key>
<string>Use Photos</string>
einen Schlüssel hinzufügen können Sie auch nur die creationRequestForAssetFromImage
Methode nicht zu mit UIImage zu machen, sondern auch mit einer Bild-URL verwenden.
Dies sind die Methoden, die Sie verwenden können von Fotos Framework.
+ (instancetype)creationRequestForAssetFromImage:(UIImage *)image;
+ (nullable instancetype)creationRequestForAssetFromImageAtFileURL:(NSURL *)fileURL;
+ (nullable instancetype)creationRequestForAssetFromVideoAtFileURL:(NSURL *)fileURL;
Swift 3,0
let image = UIImage(named: "DP.jpg")
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAsset(from: image!)
}) { (success:Bool, error:Error?) in
if success {
print("Image Saved Successfully")
} else {
print("Error in saving:"+error.debugDescription)
}
}
Die anderen Methoden für Fotos Rahmen für Swift sind:
open class func creationRequestForAsset(from image: UIImage) -> Self
open class func creationRequestForAssetFromImage(atFileURL fileURL: URL) -> Self?
open class func creationRequestForAssetFromVideo(atFileURL fileURL: URL) -> Self?
Try this http://stackoverflow.com/ Fragen/37405691/Ersetzen-AlassertLibrary-t o-get-the-filename/37405786 # 37405786 –
Mögliches Duplikat von [So speichern Sie Bilder in iPhone-Fotobibliothek?] (http://stackoverflow.com/questions/178915/how-to-save-picture-to-iphone (Foto-Bibliothek) –
Nein, diese Fragen und Antworten sind anders – kenzolek