2013-03-20 24 views
4

我從iOS4提交更新之前已經進行了測試,並且遇到以下問題:1)從我的應用程序創建PDF。 2)似乎不一致,因爲在大多數情況下,我可以創建新的PDF而不會出現問題。 3)崩潰日誌表示在ExportView的第341行發生崩潰,我已經配置了該行,以便該行上唯一的項目是CFRangeMake。在控制檯中注意有一個值,因爲在幾行中使用相同的值。libMobileGestalt copySystemVersionDictionaryValue:無法從系統版本字典中查找ReleaseType

一些注意事項:使用Xcode 4.6,目標是iOS6,完全ARC,在新iPad上進行測試。

任何幫助,將不勝感激!

我已經刪除了一些崩潰日誌和控制檯日誌來縮短這篇文章!對於它的長度,甚至現在抱歉!對於字符串

方法被應用到PDF創建:

- (CFMutableAttributedStringRef) CreateAttributedString:(int*) dateLength 
             titleLength:(int*) titleLength 
{ 
    NSLog(@"Current EntryIndex: %d", _entryIndex); 
    NSLog(@"Current Entry: %@", _currentEntry); // current entry is set from the parent view controller via PrepareForSegue 

    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setDateFormat:@"MMMM dd, yyyy, h:mm aaa"]; 
    NSString * dateString = [dateFormatter stringFromDate:_currentEntry.created]; 
    *dateLength = [dateString length]; 
    NSLog(@"DateString: %@", dateString); 
    NSLog(@"2nd DateLength: %d", *dateLength); 

    NSString *title = _entryTitle; 
    *titleLength = [title length]; 

    NSString *bodyString = _entryText; 
    NSString *contentString = [NSString stringWithFormat:@"%@\n\n%@\n%@", dateString, title, bodyString]; 
    NSLog(@"TitleString: %@", title); 
    NSLog(@"BodyString: %@", bodyString); 
    NSLog(@"TitleLength: %d", *titleLength); 

    CFStringRef string = (__bridge CFStringRef)contentString; 
    CFMutableAttributedStringRef attributedContentString CFAttributedStringCreateMutable(kCFAllocatorDefault, 0); 
    CFAttributedStringReplaceString (attributedContentString,CFRangeMake(0, 0), string); 
    return attributedContentString; 
    } 

- (void) SetTextFontName:(int)dateLength titleLength:(int)titleLength forAttributedString:(CFMutableAttributedStringRef) text 
{ 
    //date 
    CTFontDescriptorRef dateFontDescriptor = CTFontDescriptorCreateWithNameAndSize((__bridge CFStringRef)_entryDateTimeFontName, _entryDateTimeFontSize); 

    CTFontRef dateFont = CTFontCreateWithFontDescriptor(dateFontDescriptor, _entryDateTimeFontSize, NULL); 
    NSLog(@"Font entryDateTimeFontSize, line 329: %d", _entryDateTimeFontSize); 
    NSLog(@"DateFontDescriptor, line 329: %@", dateFontDescriptor); 
    CFAttributedStringSetAttribute(text, CFRangeMake(0, dateLength), kCTFontAttributeName, dateFont); 
    NSLog(@"DateLength... before crash: %d", dateLength); 
    NSLog(@"DateLength... crashing: %d", dateLength); 
    CFAttributedStringSetAttribute(text, 
           CFRangeMake(0, dateLength), // this is line 341... 
           kCTForegroundColorAttributeName, 
           _entryDateTimeColor.CGColor); 
    NSLog(@"Date length for line 332: %d", dateLength); 
    NSLog(@"Text for line 332: %@", text); 
    NSLog(@"Font name... font attributes line 332: %@", dateFont); 
    NSLog(@"Date length for line 333: %d", dateLength); 
    NSLog(@"Text for line 333: %@", text); 
    NSLog(@"Date color for line 333: %@", _entryDateTimeColor.CGColor); 
    CFRelease(dateFontDescriptor); 
    CFRelease(dateFont); 

    //title 
    CTTextAlignment alignment = kCTCenterTextAlignment; 
    CTParagraphStyleSetting _settings[] = {{kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment}}; 
    CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(_settings, sizeof(_settings)/sizeof(_settings[0])); 
    CFAttributedStringSetAttribute(text, CFRangeMake(dateLength, dateLength + titleLength), kCTParagraphStyleAttributeName, paragraphStyle); 

    CTFontDescriptorRef titleFontDescriptor = CTFontDescriptorCreateWithNameAndSize((__bridge CFStringRef)_entryTitleFontName, _entryTitleFontSize); 

    CTFontRef titleFont = CTFontCreateWithFontDescriptor(titleFontDescriptor,_entryTitleFontSize, NULL); 
    NSLog(@"TitleFontDescriptor: %@", titleFontDescriptor); 
    CFAttributedStringSetAttribute(text, CFRangeMake(dateLength, dateLength + titleLength), kCTFontAttributeName, titleFont); 
    CFAttributedStringSetAttribute(text, CFRangeMake(dateLength, dateLength + titleLength), kCTForegroundColorAttributeName, _entryTitleColor.CGColor); 
    NSLog(@"TitleColor: %@", _entryTitleColor); 
    NSLog(@"Titlecolor: %@", _entryTitleColor.CGColor); 
    CFRelease(titleFontDescriptor); 
    CFRelease(titleFont); 

    //content 
    CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithNameAndSize((__bridge CFStringRef)_entryTextFontName, _entryTextFontSize); 
    CTFontRef font = CTFontCreateWithFontDescriptor(fontDescriptor, _entryTextFontSize, NULL); 
    CFAttributedStringSetAttribute(text, CFRangeMake(dateLength + titleLength+2, CFAttributedStringGetLength(text) - dateLength - titleLength - 2), kCTFontAttributeName, font); 
    CFAttributedStringSetAttribute(text, CFRangeMake(dateLength + titleLength+2, CFAttributedStringGetLength(text) - dateLength - titleLength - 2), kCTForegroundColorAttributeName, _entryTextColor.CGColor); 
    CFRelease(fontDescriptor); 
    CFRelease(font); 
} 

崩潰日誌:

Incident Identifier: D5D15E15-8A4C-4850-B751-9F1D546F1F71 
CrashReporter Key: 54bfdcf0248d463bc97ac986b7553405b3b0f8b9 
Hardware Model:  iPad3,4 
Process:   TabletJournal [9876] 
Path:   /var/mobile/Applications/109DCB8E-22D1-45E4-A347- 1B1F211F9044/TabletJournal.app/TabletJournal 
Identifier:  TabletJournal 
Version:   ??? (???) 
Code Type:  ARM (Native) 
Parent Process: launchd [1] 

Date/Time:  2013-03-20 15:42:11.412 +0100 
OS Version:  iOS 6.1.2 (10B146) 
Report Version: 104 

Exception Type: EXC_BREAKPOINT (SIGTRAP) 
Exception Codes: 0x0000000000000001, 0x000000000000defe 
Crashed Thread: 0 

Thread 0 name: Dispatch queue: com.apple.main-thread 
Thread 0 Crashed: 
0 CoreFoundation    0x3272b4e0 0x32693000 + 623840 
1 CoreFoundation    0x3271bc2c 0x32693000 + 560172 
2 CoreFoundation    0x3277043c 0x32693000 + 906300 
3 CoreFoundation    0x32697b4e 0x32693000 + 19278 
4 CoreFoundation    0x32705e5e 0x32693000 + 470622 
5 TabletJournal     0x0005f3d8 -[ExportView SetTextFontName:titleLength:forAttributedString:] (ExportView.m:341) 
6 TabletJournal     0x0005ed58 -[ExportView saveJournalToPDF:andName:] (ExportView.m:196) 
7 TabletJournal     0x0005ec8a -[ExportView pdfButtonTapped:] (ExportView.m:179) 
8 UIKit       0x3464f082 0x34561000 + 974978 
9 UIKit       0x3464f036 0x34561000 + 974902 
10 UIKit       0x3464f010 0x34561000 + 974864 
11 UIKit       0x3464e8c6 0x34561000 + 972998 
12 UIKit       0x3464edb4 0x34561000 + 974260 
13 UIKit       0x345775f4 0x34561000 + 91636 
14 UIKit       0x345648dc 0x34561000 + 14556 
15 UIKit       0x345641ea 0x34561000 + 12778 
16 GraphicsServices    0x362575f4 0x36251000 + 26100 
17 GraphicsServices    0x36257222 0x36251000 + 25122 
18 CoreFoundation    0x3272a3e4 0x32693000 + 619492 
19 CoreFoundation    0x3272a386 0x32693000 + 619398 
20 CoreFoundation    0x3272920a 0x32693000 + 614922 
21 CoreFoundation    0x3269c238 0x32693000 + 37432 
22 CoreFoundation    0x3269c0c4 0x32693000 + 37060 
23 GraphicsServices    0x36256336 0x36251000 + 21302 
24 UIKit       0x345b82b4 0x34561000 + 357044 
25 TabletJournal     0x0002e35a main (main.m:22) 
26 libdyld.dylib     0x3aa02b1c 0x3aa01000 + 6940 

Thread 0 crashed with ARM Thread State (32-bit): 
    r0: 0x3ac440f0 r1: 0x00000000  r2: 0x00001200  r3: 0x3ac2ce44 
    r4: 0x00000000 r5: 0x1ea52580  r6: 0x3272b4d9  r7: 0x2fdd26c4 
    r8: 0x3ac47940 r9: 0x00000012  r10: 0x3acacd88  r11: 0x1ea52580 
    ip: 0x00010201 sp: 0x2fdd26c0  lr: 0x3271bc2f  pc: 0x3272b4e0 
    cpsr: 0xa0000030 

控制檯日誌...重要的部分:

Mar 20 15:50:54 Marcs-iPad TabletJournal[9947] <Warning>: SettingsModel, entries: (
"<JournalEntry: 0x1e296310>", 
"<JournalEntry: 0x1e24be00>") 
Mar 20 15:50:54 Marcs-iPad TabletJournal[9947] <Warning>: Export Loading 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: Current EntryIndex: 1 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: Current Entry: <JournalEntry: 0x1e296310> 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: DateString: marzo 20, 2013, 3:41 PM 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: 2nd DateLength: 23 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: TitleString: Test2 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: BodyString: I’m here in the Istanbul airport again, for another 5-hour layover! Plane is suppose to take off at 2:50 pm! Next time, I’m going to make sure my layovers are not more than 2 hours. That’ll leave room for delays. I ate a small pizza at this 「Italian」 diner. It was actually pretty good. Later, I’ll have to compare it with real Italian pizza. I’m dead tired. Gotta get some caffeine! Got the caffeine! Yow! I should wake up in a few minutes! There are posters of Italia here and I’ve found a couple of places I’d like to see. Lago D’Orta di Piemonte, Galleria Borghese di Lazio- Roma, Pisa. 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: TitleLength: 5 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: Font entryDateTimeFontSize, line 329: 13 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: DateFontDescriptor, line 329:  
CTFontDescriptor <attributes: <CFBasicHash 0x1d518f50 [0x3ac440f0]>{type = mutable dict, count = 2, 
entries => 
1 : <CFString 0x3acad758 [0x3ac440f0]>{contents = "NSFontNameAttribute"} = <CFString 0x1e07a880 [0x3ac440f0]>{contents = "Copperplate"} 
2 : <CFString 0x3acad8c8 [0x3ac440f0]>{contents = "NSFontSizeAttribute"} = <CFNumber 0x1d5cb1d0 [0x3ac440f0]>{value = +13.0000000000, type = kCFNumberFloat32Type}} 
> 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: DateLength... before crash: 23 
Mar 20 15:50:55 Marcs-iPad TabletJournal[9947] <Warning>: DateLength... crashing: 23 
Mar 20 15:50:56 Marcs-iPad ReportCrash[9951] <Notice>: Formulating crash report for process TabletJournal[9947] 
Mar 20 15:50:56 Marcs-iPad com.apple.launchd[1] (UIKitApplication:com.creativeappgroup.TabletJournalTM[0xe437][9947]) <Warning>: (UIKitApplication:com.creativeappgroup.TabletJournalTM[0xe437]) Job appears to have crashed: Trace/BPT trap: 5 
Mar 20 15:50:56 Marcs-iPad ReportCrash[9951] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary 
Mar 20 15:50:56 Marcs-iPad backboardd[25] <Warning>: Application 'UIKitApplication:com.creativeappgroup.TabletJournalTM[0xe437]' exited abnormally with signal 5: Trace/BPT trap: 5 
Mar 20 15:50:56 Marcs-iPad ReportCrash[9951] <Notice>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/TabletJournal_2013-03-20-155055_Marcs-iPad.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0 

回答

7

它事實證明libModileGestalt與崩潰沒有任何關係。通過蘋果論壇的小貼士發現,CGColor可能是零。在實際調用之前隔離並安裝日誌語句之後,確實如此。事實上,所有的顏色......文字,標題和日期都以NULL結尾。所以,我已經通過在創建PDF方法中安裝測試和應用語句來停止崩潰。現在...瞭解顏色爲什麼不被傳遞!

+1

感謝您的解決方案跟進您的問題! – 2013-09-17 05:37:55