私はiOSで、ふりをしたファイルのレイアウトに使用したUIKit
さまざまなファイルからPDFファイルを作成するために使用しています。XIB
PDFファイルを正常に生成できます。ただし、メインスレッドでこれを行っているので、UIが「フリーズ」しないように、メインスレッドを別のスレッドに移動したいと思います。
私はGCDでそうしようとしましたが、うまくいきませんでした、そしてそれはいくつかのエラーを投げ返しました。
私はこのようなものを持っています:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
__block NSData *pdfNote = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0),^{
pdfNote = [self generatePdfFile];
dispatch_sync(dispatch_get_main_queue(),^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
});
私が見るエラーは次のとおりです。
failed to find PDF header: `%PDF' not found.
failed to find PDF header: `%PDF' not found.
failed to find PDF header: `%PDF' not found.
failed to find PDF header: `%PDF' not found.
2012-07-12 15:31:15.427 IrmaosPeixoto-CRM[7601:1a03] bool _WebTryThreadLock(bool), 0x3404d0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1 _ZL17_WebTryThreadLockb
2 WebThreadLock
3 -[UITextView setFrame:]
4 UIViewCommonInitWithFrame
5 -[UIView initWithCoder:]
6 -[UIScrollView initWithCoder:]
7 -[UITextView initWithCoder:]
8 UINibDecoderDecodeObjectForValue
9 UINibDecoderDecodeObjectForValue
10 -[UINibDecoder decodeObjectForKey:]
11 -[UIView initWithCoder:]
12 -[UIClassSwapper initWithCoder:]
13 UINibDecoderDecodeObjectForValue
14 -[UINibDecoder decodeObjectForKey:]
15 -[UIRuntimeConnection initWithCoder:]
16 UINibDecoderDecodeObjectForValue
17 UINibDecoderDecodeObjectForValue
18 -[UINibDecoder decodeObjectForKey:]
19 -[UINib instantiateWithOwner:options:]
20 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:]
21 +[UIView(Extensions) loadFromNib:owner:]
22 -[FinishOrderViewController generatePdfFile]
23 __43-[FinishOrderViewController buttonPressed:]_block_invoke_0
24 _dispatch_call_block_and_release
25 _dispatch_worker_thread2
26 _pthread_wqthread
27 start_wqthread
追記:PDFの生成には、情報を取得するためのCoreDataへのアクセスが含まれます。
私が必要としていることを達成するためのより良い(実用的な)方法はありますか?
編集私は間違っていました、私はUIKit
PDFを生成するためにコアグラフィックスの代わりに使用しています。