2013-02-26 24 views
7

मैं अन्य ऐप्स में वेब से फ़ाइल खोलना चाहता हूं।UIDocumentInteractionController और वेब से फ़ाइल

मेरे कोड:

NSURLRequest *req = [[NSURLRequest alloc] initWithURL:url]; 
[NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *resp, NSData *respData, NSError *error){ 
    NSLog(@"resp data length: %i", respData.length); 
    NSArray *names = [objDict[@"name"] componentsSeparatedByString:@"."]; 
    NSString *fileName = [@"downloaded." stringByAppendingString:names[names.count-1]]; 
    NSString * path = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName]; 
    NSError *errorC = nil; 
    BOOL success = [respData writeToFile:path 
       options:NSDataWritingFileProtectionComplete 
        error:&errorC]; 

    if (success) { 
     UIDocumentInteractionController *documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]]; 
     documentController.delegate = self; 
     [documentController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES]; 
    } else { 
     NSLog(@"fail: %@", errorC.description); 
    } 
}]; 

यह पैनल से पता चलता है, लेकिन किसी भी बटन को क्लिक पर दुर्घटनाओं (नहीं 'रद्द करें' केवल)। अपने UIDocumentInteractionControllerNSURLConnectionsendAsynchronousRequest ब्लॉक से बाहर

-[UIDocumentInteractionController URL]: message sent to deallocated instance 

उत्तर

3

लें:

मैं ज़ोंबी वस्तुओं सक्षम है और यह लिखता है।

कनेक्शन इंटरैक्शन नियंत्रक को कनेक्शन पूरा होने के लगभग लंबे समय तक रहना पड़ता है, लेकिन यह ब्लॉक पर स्कॉप्ड होता है। ब्लॉक खत्म होने के बाद, इसका कोई संदर्भ नहीं होगा और इसे हटा दिया जाएगा।

5

मुझे एक ही समस्या थी, लेकिन मैं एक ब्लॉक के अंदर अपना UIDocumentInteractionController प्रारंभ नहीं कर रहा था। मैंने इसे अपनी इंटरफ़ेस फ़ाइल में एक संपत्ति का उपयोग करके हल किया ताकि कक्षा UIDocumentInteractionController के उदाहरण पर दृढ़ता से हो।

@property (nonatomic, strong) UIDocumentInteractionController *documentController; 
संबंधित मुद्दे