cordova-plugin-printer icon indicating copy to clipboard operation
cordova-plugin-printer copied to clipboard

ios 14 print crash

Open kirtipriya opened this issue 5 years ago • 15 comments

App crashes when cancel button is clicked from Print in ios 14

void _WebThreadLock(), 0x1069ec420: 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...

kirtipriya avatar Sep 22 '20 16:09 kirtipriya

@kirtipriya - Have you faced this too ? https://github.com/katzer/cordova-plugin-printer/issues/266

Anuj-logiciel avatar Sep 29 '20 15:09 Anuj-logiciel

@kirtipriya - Have you faced this too ? #266

Hello Anuj , I have not faced #266 . But to fix my crash , i used html2pdf to convert the html to pdf in base 64 format , and then i passed this base 64 output to the printer plugin. Can you try this too?

kirtipriya avatar Sep 30 '20 16:09 kirtipriya

Hi kirtipriya... Yep, just came across this issue too. The XCode debugger suggests that iOS 14 requires this to run in a background thread. Have included some relevant output below that may assist in resolving this... Hope it helps!

Plugin should use a background thread. Unable to simultaneously satisfy constraints. ( "<NSLayoutConstraint:0x600002973570 UIView:0x7fc44a730760.width == UILabel:0x7fc44a4330a0.width + 28 (active)>", "<NSLayoutConstraint:0x600002973520 H:[UIImageView:0x7fc44a72f460]-(3)-UILabel:0x7fc44a4330a0 (active)>", "<NSLayoutConstraint:0x6000029733e0 UIImageView:0x7fc44a72f460.width == 22 (active)>", "<NSLayoutConstraint:0x6000029732a0 H:|-(0)-UIImageView:0x7fc44a72f460 (active, names: '|':UIView:0x7fc44a730760 )>", "<NSLayoutConstraint:0x600002973250 UILabel:0x7fc44a4330a0.right == UIView:0x7fc44a730760.right (active)>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002973520 H:[UIImageView:0x7fc44a72f460]-(3)-UILabel:0x7fc44a4330a0 (active)> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 2020-10-18 18:54:29.562855+1100 void _WebThreadLock(), 0x101d6e100: 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...

gpreg avatar Oct 18 '20 10:10 gpreg

@kirtipriya - Have you faced this too ? #266

Hello Anuj , I have not faced #266 . But to fix my crash , i used html2pdf to convert the html to pdf in base 64 format , and then i passed this base 64 output to the printer plugin. Can you try this too?

Possible to share your code using html2pdf?

macsupport avatar Oct 19 '20 18:10 macsupport

@kirtipriya - Have you faced this too ? #266

Hello Anuj , I have not faced #266 . But to fix my crash , i used html2pdf to convert the html to pdf in base 64 format , and then i passed this base 64 output to the printer plugin. Can you try this too?

Possible to share your code using html2pdf?

cordova.plugins.pdf.htmlToPDF({ data: htmlContent, documentSize: "A4", landscape: "portrait", type: "base64", footer: footerContent }, (sucess) => { console.log('success: ', success); cordova.plugins.printer.print('base64://' + success); }, (error) => console.log('error:', error)); }); }

kirtipriya avatar Oct 20 '20 12:10 kirtipriya

Hi base64 solution is not working for me, still getting the same crash : void _WebThreadLock(), 0x133db9500: 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... it is only occurring with ios 14. can anyone please assist with it. Thanks

poojachaudhary1 avatar Nov 16 '20 00:11 poojachaudhary1

Same for me. 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.

1nstinct avatar Dec 14 '20 04:12 1nstinct

Anybody who wants quick solution can install plugin from here. All working fine with WKWebview.

Anuj-logiciel avatar Dec 23 '20 05:12 Anuj-logiciel

Used the base64 solution suggested by @kirtipriya - it works for me

1nstinct avatar Dec 28 '20 03:12 1nstinct

Can anyone suggest the right solution for this problem, we are facing same issue. does upgrading to latest version would be of any help? current version in use => 0.7.3

prvinuch avatar Apr 23 '21 19:04 prvinuch

I ended up changing to a different plugin (cordova-pdf-generator) - it may suit depending on your needs.

gpreg avatar Apr 24 '21 01:04 gpreg

I ended up changing to a different plugin (cordova-pdf-generator) - it may suit depending on your needs.

Does it serve same purpose as this plugin.

prvinuch avatar Apr 24 '21 19:04 prvinuch

It was able to do what we had been previously been using cordova-plugin-printer for - but you'll need to check the details (https://www.npmjs.com/package/cordova-pdf-generator) against you're own app's requirements.

gpreg avatar Apr 25 '21 00:04 gpreg

Hi Guys, Can someone please let me know how do we use this block and basically which method to be called from inside of this block ?? I tried few things but see the same behaviour. Everyone else is saying that this block should fix the crash issue but somehow it does not change the behaviour yet. What I think is it is not the base64 or html content which is the issue, it is the way in which the UIKit is being called from the plugin code.

Which exact block of code do we need to call from this ?

dispatch_sync(dispatch_get_main_queue(), ^{

//Your code goes here

});

avbapat avatar Nov 16 '21 08:11 avbapat

@kirtipriya can you please help ?

avbapat avatar Nov 16 '21 17:11 avbapat