विफल रहता है मैं एक ऐप विकसित कर रहा हूं जो उपयोगकर्ताओं को फोटोकिट का उपयोग करके फोटो संपादित करने की अनुमति देता है। मैं पहले संपादित तस्वीर को एक जेपीईजी के रूप में डिस्क में सहेज रहा था। मैं जेपीईजी में परिवर्तित होने से बचना चाहता हूं और ऐसा करने के लिए संशोधनों को लागू करना चाहता हूं। यह कैमरे के साथ ली गई तस्वीरों के लिए बहुत अच्छा काम करता है, लेकिन यदि आप स्क्रीनशॉट को संपादित करने का प्रयास करते हैं, तो PHPhotoLibrary.sharedPhotoLibrary().performChanges
ब्लॉक विफल हो जाएगा और The operation couldn’t be completed. (Cocoa error -1.)
लॉग इन करेगा। मुझे यकीन नहीं है कि यह निष्पादन चेंज ब्लॉक को विफल क्यों कर रहा है, मैंने यहां क्या गलत किया है?स्क्रीनशॉट संपादित करने में असमर्थ, प्रदर्शन चेंज ब्लॉक
मैंने sample app available to download बनाया है जो समस्या का प्रदर्शन करता है, और मैंने नीचे प्रासंगिक कोड शामिल किया है। ऐप आपकी फोटो लाइब्रेरी में नवीनतम तस्वीर को संपादित करने का प्रयास करता है। यदि यह सफल होता है तो यह फ़ोटो को संपादित करने के लिए पहुंच के लिए संकेत देगा, अन्यथा कुछ भी नहीं होगा और आपको कंसोल लॉग दिखाई देगा। इस मुद्दे को पुन: उत्पन्न करने के लिए, स्क्रीनशॉट लें और फिर ऐप चलाएं।
वर्तमान कोड है कि स्क्रीनशॉट के साथ काम करता है:
let jpegData: NSData = outputPhoto.jpegRepresentationWithCompressionQuality(0.9)
let contentEditingOutput = PHContentEditingOutput(contentEditingInput: self.input)
var error: NSError?
let success = jpegData.writeToURL(contentEditingOutput.renderedContentURL, options: NSDataWritingOptions.AtomicWrite, error: &error)
if success {
return contentEditingOutput
} else {
return nil
}
रिप्लेसमेंट कोड का कारण बनता है कि स्क्रीनशॉट विफल:
let url = self.input.fullSizeImageURL
let orientation = self.input.fullSizeImageOrientation
var inputImage = CIImage(contentsOfURL: url)
inputImage = inputImage.imageByApplyingOrientation(orientation)
let outputPhoto = createOutputImageFromInputImage(inputImage)!
let originalImageData = NSData(contentsOfURL: self.input.fullSizeImageURL)!
let imageSource = CGImageSourceCreateWithData(originalImageData, nil)
let dataRef = CFDataCreateMutable(nil, 0)
let destination = CGImageDestinationCreateWithData(dataRef, CGImageSourceGetType(imageSource), 1, nil) //getType automatically selects JPG, PNG, etc based on original format
struct ContextStruct {
static var ciContext: CIContext? = nil
}
if ContextStruct.ciContext == nil {
let eaglContext = EAGLContext(API: .OpenGLES2)
ContextStruct.ciContext = CIContext(EAGLContext: eaglContext)
}
let cgImage = ContextStruct.ciContext!.createCGImage(outputPhoto, fromRect: outputPhoto.extent())
CGImageDestinationAddImage(destination, cgImage, nil)
if CGImageDestinationFinalize(destination) {
let contentEditingOutput = PHContentEditingOutput(contentEditingInput: self.input)
var error: NSError?
let imageData: NSData = dataRef
let success = imageData.writeToURL(contentEditingOutput.renderedContentURL, options: .AtomicWrite, error: &error)
if success {
//it does succeed
return contentEditingOutput
} else {
return nil
}
}
मैंने ऐप्पल के साथ एक बग लॉग किया है। यह बग आईओएस 9 और 10 में भी मौजूद है। स्पष्ट रूप से उनके लिए ठीक करने के लिए उच्च प्राथमिकता नहीं है। – jjxtra