2017-06-10 2 views

Antwort

4

Asset = Hier müssen Sie Ihre PHAsset passieren.

PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc] init]; 
[[PHImageManager defaultManager] 
      requestImageDataForAsset:asset 
          options:imageRequestOptions 
         resultHandler:^(NSData *imageData, NSString *dataUTI, 
             UIImageOrientation orientation, 
             NSDictionary *info) 
    { 
      NSLog(@"info = %@", info); 
      if ([info objectForKey:@"PHImageFileURLKey"]) { 

       NSURL *path = [info objectForKey:@"PHImageFileURLKey"]; 
       // if you want to save image in document see this. 
       [self saveimageindocument:imageData withimagename:[NSString stringWithFormat:@"DEMO"]]; 
      }            
    }]; 

-(void) saveimageindocument:(NSData*) imageData withimagename:(NSString*)imagename{ 

    NSString *writePath = [NSString stringWithFormat:@"%@/%@.png",[Utility getDocumentDirectory],imagename]; 

    if (![imageData writeToFile:writePath atomically:YES]) { 
     // failure 
     NSLog(@"image save failed to path %@", writePath); 

    } else { 
     // success. 
     NSLog(@"image save Successfully to path %@", writePath); 
    } 

} 
+ (NSString*)getDocumentDirectory { 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    return [paths objectAtIndex:0]; 
} 

prüfen Bild, das Querformat oder Hochformat-Modus

if (chooseimage.size.height >= chooseimage.size.width) 
{ 
     Islandscape = NO; 
}else{ 
    UIImage* landscapeImage = [UIImage imageWithCGImage:chooseimage.CGImage 
                 scale:chooseimage.scale 
               orientation:UIImageOrientationLeft]; 
     self.imgPreviewView.image = landscapeImage; 
     self.imgPreviewView.contentMode = UIViewContentModeScaleAspectFill; 
     Islandscape = YES; 
} 

Fügen Sie diese Erlaubnis in info.plist Datei

<key>NSPhotoLibraryUsageDescription</key> 
<string>$(PRODUCT_NAME) would like to access your photo library to let you select a picture.</string> 
+0

Danke für ans Ich versuchte Ihr Ans, aber ich erhalte diese Art Fehler print auf Protokoll :: Einstellung Sicherheitsinformationen: Betrieb nicht erlaubt und auch ich versuche, Bild von Phasset URL zu Dokument Direcory zu speichern, aber ich bekomme den Fehler - Zugriff nicht aus Sicherheitsgründen zulassen. – Keyur

+0

Sie müssen eine Sache in der Datei info.plist hinzufügen, die ich in meiner Antwort hinzugefügt habe. @KeyurAspiration –

+0

Ich habe bereits in info.plist hinzugefügt wie Foto, Kamera, MicroPhone Beschreibung Zugriff, eine weitere Sache und andere Weise Array von Bildern speichern in Dokument-Verzeichnis mit aus dem Speicher Warnung issue.so bitte sagen Sie mir. – Keyur

1

Sie können die imageURL von PHContentEditingInput erhalten:

Swift:

asset.requestContentEditingInput(with: PHContentEditingInputRequestOptions()) { (eidtingInput, info) in 
    if let input = eidtingInput, let imgURL = input.fullSizeImageURL { 
    // imgURL 
    } 
} 

Objective-C:

[asset requestContentEditingInputWithOptions:[PHContentEditingInputRequestOptions new] completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) { 
    NSURL *imageURL = contentEditingInput.fullSizeImageURL; 
}]; 
+0

Antwort klar @ a-tuo Bitte antworten Sie in Objective-C, weil ich keine Ahnung habe in Swift – Keyur

+0

@KeyurAspiration Haben Sie die "Privacy - Photo Library Verwendungsbeschreibung" Taste in PLIST hinzugefügt, um die Erlaubnis zum Zugriff auf Phot zu erhalten os? –

+0

@ a-tuo Ja, ich habe bereits "Datenschutz - Fotobibliothek Verwendung Beschreibung" angegeben. – Keyur

Verwandte Themen