Ниже приводится то, что я использую для своего приложения. Это очень хорошо работает в iOS 7, но сбой в iOS 8.Сбой в iOS 8 при вызове UIGraphicsEndPDFContext при создании pdf
Используя этот метод, я беру снимок экрана и создаю 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();
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:30.0/255.0 green:172.0/255.0 blue:254.0/255.0 alpha:1]];
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Payment Receipt"];
[mailer addAttachmentData:pdfData mimeType:@"application/pdf" fileName:[NSString stringWithFormat:@"%@",aFilename]];
NSString *emailBody = @"Payment Receipt";
[mailer setMessageBody:emailBody isHTML:NO];
[[mailer navigationBar] setTintColor:[UIColor whiteColor]];
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email error!"
message:@" You do not have an email address configured in your device"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
Когда я добавляю Exception точки останова, я вижу, что он останавливается на UIGraphicsEndPDFContext()
пытаются найти выход последние 3 дня без успеха.
Вы нашли «отправить почту» часть кода (и вопрос) имеет отношение к ошибка? – usr2564301
Они не являются частью ошибки. Но никакого вреда при размещении полного кода, поскольку он дает полную видимость. –