2016-01-29 5 views
6

मेरे फोटो एक्सटेंशन ऐप में कैमरा और फ़ोटो दोनों तक पहुंच है। सब ठीक है, लेकिन दबाते समय हो गया, यह छवि को सहेज नहीं सकता है।आईओएस फोटो एक्सटेंशन फिनिशकंटेंट एडिटिंग विथ कॉम्प्लेशन हैंडलर: परिवर्तनों को सहेजने में असमर्थ

मानक पूरा होने हैंडलर के कोड:

- (void)finishContentEditingWithCompletionHandler:(void (^)(PHContentEditingOutput *))completionHandler { 
    // Update UI to reflect that editing has finished and output is being rendered. 

    // Render and provide output on a background queue. 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     PHContentEditingOutput *output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input]; 

     NSError* error = nil; 

     NSData *renderedJPEGData = UIImageJPEGRepresentation(filtered_ui_image, 1.0); 
     assert(renderedJPEGData != nil); 
     //BOOL written_well = [renderedJPEGData writeToURL:output.renderedContentURL atomically:YES]; 

     BOOL written_well = [renderedJPEGData writeToURL:output.renderedContentURL options:NSDataWritingAtomic error:&error]; 
     assert(written_well); 



     // Call completion handler to commit edit to Photos. 
     completionHandler(output); 
    }); 
} 

renderedJPEGData, nil नहीं है,
errornil है, इस प्रकार समारोह [NSData writeToURL] सफल रहा था,
written_wellYES है

जब डिबगिंग लाइन-दर- लाइन खत्म होने के बाद, एक चेतावनी प्रकट होती है: enter image description here

output.renderedContentURL/private/var/mobile/Containers/Data/PluginKitPlugin/509C1A04-D414-4DB7-B1E6-83C47FC88BC9/tmp/blah_blah_name.JPG

तो है, मैं अनुमतियाँ है, डिबग कोई त्रुटि पता चलता है, कि मैं क्या इस समस्या का कारण पता लगाने के लिए कोशिश कर सकते हैं?

उत्तर

0

यहां तक ​​कि शीर्ष लेख का तात्पर्य है कि adjustmentData नहीं के बराबर हो सकता है, हालांकि, प्रलेखन राज्यों:

आप URL renderedContentURL संपत्ति द्वारा निर्दिष्ट करने के लिए नए संपत्ति सामग्री लिखने हैं, तो आप भी एक नया, अलग PHAdjustmentData प्रदान करनी चाहिए आपके संपादन का वर्णन करने वाली वस्तु। एक पूर्ववर्ती समायोजन डेटा ऑब्जेक्ट (जो पहले संपादन का वर्णन करता है) को पास करना अपरिभाषित व्यवहार में परिणाम देता है।

तो पूरा होने हैंडलर कॉल करने से पहले कुछ इस तरह करते हैं:

output.adjustmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"com.whatever.app" formatVersion:@"1.0" data:[NSData data]]; 
4

आईओएस 10 के रूप में, समायोजन डेटा कम से कम एक बाइट होना आवश्यक है। यह आईओएस 9 से एक तोड़ने वाला बदलाव है, जहां समायोजन डेटा शून्य हो सकता है। मैंने पुष्टि करने के लिए आईओएस 9 और आईओएस 10 दोनों पर इसका परीक्षण किया है।

अतिरिक्त दस्तावेज़: https://developer.apple.com/reference/photos/phcontenteditingoutput/1518684-adjustmentdata

PHContentEditingOutput* output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input]; 
NSMutableData* adjustmentData = [NSMutableData data]; 
uint8_t byte = 1; 
[adjustmentData appendBytes:&byte length:1]; 
output.adjustmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"com.yourcompany.yourapp" formatVersion:@"1.0f" data:adjustmentData]; 
संबंधित मुद्दे