App Crash on iOS 12.4.3
Closed this issue · 17 comments
Hi there, thanks for opening up this issue.
Please provide a code example for me to reproduce this issue, only using this screenshot it is impossible to analyse whats going on
Hi , thanks for replying . It's working fine in iOS 13 & upper version , when it's come to iOS 12 and lover version it's causing crash in PDFCalculations.swift class . I don't know why it's happens? , I am creating pdf using section .
let document = PDFDocument(format: .a4)
// Set document meta data
document.info.title = "TRANSACTION RECEIPT"
// Set spacing of header and footer
document.layout.space.header = 5
document.layout.space.footer = 5
// Add custom pagination, starting at page 1 and excluding page 3
document.pagination = PDFPagination(container: .footerRight, style: PDFPaginationStyle.customClosure { (page, total) -> String in
return "\(page) / \(total)"
}, range: (1, 1), hiddenPages: [1, 1], textAttributes: [
.font: UIFont.boldSystemFont(ofSize: 15.0),
.foregroundColor: UIColor.black
])
// Define doccument wide styles
let titleStyle = document.add(style: PDFTextStyle(name: "Title",
font: UIFont(name: "Nunito-Bold", size: 30),
color: UIColor.black))
document.add(.contentLeft, textObject: PDFSimpleText(text: "TRANSACTION RECEIPT", style: titleStyle))
document.add(space: 15.0)
// let subTitleStyle = document.add(style: PDFTextStyle(name: "Title",
// font: UIFont(name: "Nunito-Bold", size: 18),
// color: UIColor.darkText))
let amount = NSMutableAttributedString(string: "\(self.lobjData?.currency ?? "RM") \(self.lobjData?.amount ?? "0.0")", attributes: [
.font: UIFont(name: "Nunito-Bold", size: 18) ?? UIFont.systemFont(ofSize: 18.0),
.foregroundColor: UIColor.black
])
//document.add(.contentLeft, attributedText: amount)
// document.add(.headerLeft,attributedText:amount )
// Add some spacing below subtitle
// document.add(space: 10.0)
let status = NSMutableAttributedString(string:/self.lobjData?.status_name, attributes: [
.font: UIFont(name: "Nunito-Regular", size: 18) ?? UIFont.systemFont(ofSize: 18.0),
.foregroundColor: getTransactionStatusColor(strStsus: /self.lobjData?.status_name )
])
// document.add(.contentRight, attributedText: status)
// document.add(.headerRight,attributedText:status )
// Add some spacing below subtitle
// document.add(space: 10.0)
let section = PDFSection(columnWidths: [0.5, 0.5])
section.columns[0].add(.left, attributedText: amount)
section.columns[1].add(.left, attributedText: status)
document.add(section: section)
document.add(space: 8.0)
let type = NSMutableAttributedString(string: /self.lobjData?.merchant_name , attributes: [
.font: UIFont(name: "Nunito-Bold", size: 18) ?? UIFont.systemFont(ofSize: 18.0),
.foregroundColor: UIColor.black
])
document.add(.contentLeft, attributedText: type)
document.add(space: 20.0)
let result = arrDetails.contains { (fileds) -> Bool in
fileds.image == 1
}
if (result == true) {
for (_,item) in arrDetails.enumerated() {
print(/item.name)
if item.image == 0 {
let title = NSMutableAttributedString(string: "\(/item.name)", attributes: [
.font: UIFont(name: "Nunito-Regular", size: 15) ?? UIFont.systemFont(ofSize: 15.0),
.foregroundColor: UIColor.darkText
])
// document.add(.contentLeft, attributedText: title)
// Add some spacing below subtitle
// document.add(space: 5.0)
print("item.value \(/item.value)")
let value = NSMutableAttributedString(string: "\(/item.value)", attributes: [
.font:UIFont(name: "Nunito-Bold", size: 18) ?? UIFont.systemFont(ofSize: 18.0),
.foregroundColor: UIColor.black
])
// document.add(.contentRight, attributedText: value)
// Add some spacing below subtitle
// document.add(space: 15.0)
let section = PDFSection(columnWidths: [0.5, 0.5])
section.columns[0].add(.left, attributedText: title)
section.columns[1].add(.left, attributedText: value)
document.add(section: section)
document.add(space: 15.0)
}else{
print(/item.name)
let title = NSMutableAttributedString(string: "\(/item.name)", attributes: [
.font: UIFont(name: "Montserrat-Bold", size: 18) ?? UIFont.systemFont(ofSize: 18.0),
.foregroundColor: UIColor.black
])
document.add(.contentCenter, attributedText: title)
document.add(space: 5.0)
// let section = PDFSection(columnWidths: [0.3, 0.3])
// section.columns[0].add(.left, attributedText: title)
// section.columns[1].add(.right, attributedText: value)
// document.add(section: section)
// document.add(space: 15.0)
}
}
}else{
for (_,item) in arrDetails.enumerated() {
print(/item.name)
let title = NSMutableAttributedString(string: "\(/item.name )", attributes: [
.font: UIFont(name: "Nunito-Regular", size: 15) ?? UIFont.systemFont(ofSize: 15.0),
.foregroundColor: UIColor.darkText
])
// document.add(.contentLeft, attributedText: title)
// Add some spacing below subtitle
// document.add(space: 5.0)
print("item.value \(/item.value)")
let value = NSMutableAttributedString(string: "\(/item.value)", attributes: [
.font:UIFont(name: "Nunito-Bold", size: 18) ?? UIFont.systemFont(ofSize: 18.0),
.foregroundColor: UIColor.black
])
// document.add(.contentRight, attributedText: value)
// Add some spacing below subtitle
// document.add(space: 15.0)
let section = PDFSection(columnWidths: [0.5, 0.5])
section.columns[0].add(.left, attributedText: title)
section.columns[1].add(.left, attributedText: value)
document.add(section: section)
document.add(space: 15.0)
}
}
do {
// Generate PDF file and save data it in a temporary file. This returns the file data to the temporary file
let lobjData = try PDFGenerator.generateData(document:
document,progress: { ( progressValue: CGFloat) in
print("progress:", progressValue)
})
let url = self.saveTablePdf(data: lobjData)
self.sharePdf(path: url)
// Load PDF into a webview from the temporary file
} catch {
print("Error while generating PDF: " + error.localizedDescription)
}
thanks for the sample code, I will take a look at it as soon as I find the time.
What version of TPDF and Swift version are you using?
Hi, thanks for answer. Swift version 5.0 ,
TPDF version 1.4 I think.
I think error cause because of some Objective c helper class or framework might you use.
I got this warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.
alright, that is a pretty old version, as the newest 1.X is 1.6 and I released 2.0.0 a little while ago.
Also TPPDF doesn't use any frameworks (except for testing) other than built-in CoreText, CoreGraphics and UIKit, also it is written in pure Swift, therefore this might be an iOS error.
Anyway, I'll try to reproduce the issue for 1.4, and if it has been resolved in the meantime.
Please also test the newer versions for your use case
I just took a look at the code sample you provided me, and again I need to ask you to provide me a piece of code I can use to reproduce the issue! Your code contains some kind of data(-structure) you did not provide, e.g. what arrDetails
is.
I also need your exact TPPDF version, as 1.4 can not be correct, as I added PDFTextStyle
in 1.5
Hi Thanks for answer, I think TPPDF version is 1.6 . and as for arrDetails you can put an object with key value pair of string like title and value ,and value can be image url also .
Hi, this can't be true either, as I changed PDFGenerator.generateData
from a static method
to an instance method
in 1.6.0, but your code sample still uses the static one.
Anyway I recreated a small sample, but I can not reproduce the issue.
My guess: it's your data that causes issues.
Is it possible you provide me with the bounds
and the text
when the issue occurs in calculateTextSizeAndRemainder
? One way would be printing it using (lldb) print bounds
and (lldb) po bounds
for both values
Hi Thanks for answer , bounds is 474,722 and text is null , but I don't understand why null is passing as text in iPhone 5 when the same work on iPhone 6 or iOS 13 and later .
TRANSACTION RECEIPT{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSFont = "<UICTFont: 0x102c40720> font-family: \"Nunito\"; font-weight: bold; font-style: normal; font-size: 30.00pt";
NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
}
then just after crash
error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value couldn't be evaluated
error: Trying to put the stack in unreadable memory at: 0x16ef1bec0.
Interesting, I also do not understand how a null object could pass if Swift is type-checking it.
So the erroneous atttributed string is actually the one you are adding per?
document.add(.contentLeft, textObject: PDFSimpleText(text: "TRANSACTION RECEIPT", style: titleStyle))
If you remove all methods afterwards, so basically creating an empty document with just the title, is it still crashing? I want to reduce the possibilities for the crash before going into it even deeper.
As you now mentioned iPhone 5, can you please list me all simulator configurations where you experience the issue, like this;
- iPhone 6, iOS 12.4
- ...
Hi Thanks for answer , I was using Real Device not simulator. So when I test in iPhone 6 it's work and when I test in iPhone 5 it's failed . can't figure out , it's not working iOS any device under 13 .
iPhone 6, iOS 12.4.5 not working
Iphone 5 , iOS 12.4.5 not working
iPhone 6s iOS 13.0.1 and latter working fine
And yes you are right If I remove all methods afterwards, so basically creating an empty document will work with all device .
And even if I add title it will crash . so what I understand that may be crash because of custom font and attributed text may be I was wrong ?
If I remove custom font with attributed then it work . hope now you get what exact causing ?
that's good news, so I think this is an issue with CoreText and I might be able to reproduce a simple test case.
Is the font Nunito
the one on Google Font or a built-in font?
Yes Nunito is a Google Font that added custom in project.
Sorry I was never able to fix this issue for you (time issues). I will close this issue now as iOS 12.4.3 is now very old and therefore a lot might have changed in the meantime. If this issue still exists on iOS 15, please feel free to reopen