Публикация Pdf из контроллера активности facebook и twitter

У меня есть код, который преобразует мой UIView в pdf. Теперь я хочу иметь возможность использовать этот PDF-файл в интеграции UIActivityController для Facebook и Twitter. Я не знаю, как это сделать, но код для PDF отображается ниже:

-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];
    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

    [aView.layer renderInContext:pdfContext];

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

    // Retrieves the document directories from the iOS device
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

    // instructs the mutable data object to write its context to a file on disk
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}

Как инициализировать PDF для публикации в Facebook и Twitter и даже по электронной почте?


person kunle kembi    schedule 16.09.2013    source источник


Ответы (1)


К сожалению, вы не можете загрузить pdf в Facebook и Twitter. Вероятно, будет лучше, если у вас есть FTP-сервер для загрузки.

Вы можете отправить по почте и распечатать его, проверьте это

    NSURL * url = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: @ "data" ofType: @ "pdf"]];
    UIActivityViewController *act=[[UIActivityViewController alloc]initWithActivityItems:@[url] applicationActivities:nil];
    [self presentViewController:act animated:YES completion:nil];
person Toseef Khilji    schedule 17.09.2013