katzer / cordova-plugin-background-mode

Keep app running in background
Apache License 2.0
1.38k stars 1k forks source link

Compatability with Ionic WKWebView #317

Open mino922 opened 6 years ago

mino922 commented 6 years ago

I am having an issue launching my Ionic app with this plugin installed and wkwebview. I posted an issue on the wkwebview forum, but the problem appears to be related to this plugin.

Here is the error I get in the xcode console

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<WKWebViewConfiguration 0x6040001ef700> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key _requiresUserActionForMediaPlayback.' * First throw call stack: ( 0 CoreFoundation 0x00000001129151cb __exceptionPreprocess + 171 1 libobjc.A.dylib 0x00000001118d8f41 objc_exception_throw + 48 2 CoreFoundation 0x0000000112915119 -[NSException raise] + 9 3 Foundation 0x00000001112fb1e3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292 *4 0x000000010c014bf6 43+[APPBackgroundMode swizzleWKWebViewEngine]_block_invoke + 358 5 ** 0x000000010c1097d2 -[CDVWKWebViewEngine pluginInitialize] + 850 6 0x000000010c13556b -[CDVViewController registerPlugin:withClassName:] + 315 7 0x000000010c134c7c -[CDVViewController newCordovaViewWithFrame:] + 1404 8 0x000000010c135182 -[CDVViewController createGapView] + 354 9 0x000000010c1326d6 -[CDVViewController viewDidLoad] + 566 10 0x000000010c013506 -[MainViewController viewDidLoad] + 54 11 UIKit 0x000000010e9b9d51 -[UIViewController loadViewIfRequired] + 1235 12 UIKit 0x000000010e9ba19e -[UIViewController view] + 27 13 UIKit 0x000000010e88dd17 -[UIWindow addRootViewControllerViewIfPossible] + 122 14 UIKit 0x000000010e88e41f -[UIWindow _setHidden:forced:] + 294 15 UIKit 0x000000010e8a12bf -[UIWindow makeKeyAndVisible] + 42 16 0x000000010c136fc8 -[CDVAppDelegate application:didFinishLaunchingWithOptions:] + 776 17 0x000000010c013287 -[AppDelegate application:didFinishLaunchingWithOptions:] + 199 18 UIKit 0x000000010e81335a -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 267 19 UIKit 0x000000010e814db7 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4105 20 UIKit 0x000000010e81a245 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720 21 UIKit 0x000000010ebd5c6c 111-[UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924 22 UIKit 0x000000010efa33ef +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153 23 UIKit 0x000000010ebd5865 -[UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249 24 UIKit 0x000000010ebd60c3 -[UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 668 25 UIKit 0x000000010f533c11 82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262 26 UIKit 0x000000010f533aca -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444 27 UIKit 0x000000010f221b9c 125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 420 28 UIKit 0x000000010f41cc3e _performActionsWithDelayForTransitionContext + 100 29 UIKit 0x000000010f221998 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231 30 UIKit 0x000000010efa2a4c -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392 31 UIKit 0x000000010e818ac6 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523 32 UIKit 0x000000010ede1523 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369 33 FrontBoardServices 0x000000011a07b158 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338 34 FrontBoardServices 0x000000011a083c4d 56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235 35 libdispatch.dylib 0x0000000113a1a43c _dispatch_client_callout + 8 36 libdispatch.dylib 0x0000000113a1faf4 _dispatch_block_invoke_direct + 592 37 FrontBoardServices 0x000000011a0af672 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24 38 FrontBoardServices 0x000000011a0af328 -[FBSSerialQueue _performNext] + 464 39 FrontBoardServices 0x000000011a0af897 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 40 CoreFoundation 0x00000001128b82b1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 41 CoreFoundation 0x0000000112957d31 CFRunLoopDoSource0 + 81 42 CoreFoundation 0x000000011289cc19 CFRunLoopDoSources0 + 185 43 CoreFoundation 0x000000011289c1ff __CFRunLoopRun + 1279 44 CoreFoundation 0x000000011289ba89 CFRunLoopRunSpecific + 409 45 GraphicsServices 0x0000000116d0b9c6 GSEventRunModal + 62 46 UIKit 0x000000010e81bd30 UIApplicationMain + 159 47 *** 0x000000010c0131a1 main + 65 48 libdyld.dylib 0x0000000113a96d81 start + 1 49 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

dylanvdmerwe commented 6 years ago

Duplicate of https://github.com/katzer/cordova-plugin-background-mode/issues/307

PR which may fix it already waiting here https://github.com/katzer/cordova-plugin-background-mode/pull/315

manucorporat commented 6 years ago

Here maintainer of the Ionic's WkWebView plugin. I offer my help to get a fix to this problem merged as soon as possible, it is causing a lot troubles to our users and now WK has been enabled by default, so things will get worse.

cc @katzer what do you think?

mino922 commented 6 years ago

Can I have an update on the status of this issue?

Thank you!

klochko7 commented 6 years ago

Good day ! Any more progress on this issue ?

osterland commented 6 years ago

i fixed the underscore in my plugin manually( #315 ), so the app doesn't crash at the start. But the background mode is still not working as expected - can anybody confirm this?

dovk commented 6 years ago

Why does Ionic continuously release things like that?!

dylanvdmerwe commented 6 years ago

What do you mean? This issue is with making this plugin to work with the WkWebview in iOS 10+ which is enabled through ionic's (and Cordova's seperate) plugins. The issue is with this plugin, not Ionic.

meggillespie commented 6 years ago

@katzer I'm getting the same issue on latest dev build of my app. Just installed the plugin, ran build etc and the app freezes on the splash screen...no bueno.

'[<WKWebViewConfiguration 0x1c01e7800> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key _requiresUserActionForMediaPlayback.'

Confirm w/ @osterland ...removing '_' from the /plugins/.../etc/APPBackgroundMode.m file line: 270 gets around the error, but this seems hacky. It seems there's a pr for a fix but it's not being implemented? Rest of the plugin seems to work as it's supposed to with the underscore removed.

osterland commented 6 years ago

@manucorporat do you have any insights on this? we are really screwd without a working combination of WKWeb and a reliable background mode :/

cheers buddy!

gnesher commented 6 years ago

This bug is almost two months old now, any updates? I'm using the @osterland fix but this is making me slightly uncomfortable :/

katzer commented 6 years ago

Sorry, haven't had the time yet to look into this issue and the others.

osterland commented 6 years ago

i hope it'll help a bit:

It looks like im not able to push or pop views, when the app is in background. I'm starting to think it could be some flavour of #321 in there. So i tried to get rid of all animations ( they need timers ) but still no luck for me :/ Any suggestions?

pabloweinx commented 6 years ago

Hi @osterland . Do you have any news on this issue? We are not able to:

So we're not leveraging any feature of this evolved engine.

  • Load assets to draw markers of google maps (. We're specifying routes like: icon: 'assets/icon.png', icon: './assets/icon.png', icon: '/assets/icon.png', icon: file:///assets/icon.png, etc etc, obtaining always the following message:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCache setObject:forKey:cost:]: attempt to insert nil value (key: http:/localhost:8080/var/containers/Bundle/Application/XXXX-XXXXXX/AppName.app/www/index.html#/./assets/icon.png)'

This is not happening when using UIWebView.

Can you help us? Thanks.

b1ueRa1n commented 6 years ago

I also have this problem,This issue should be write in readme.md

Melcus commented 6 years ago

Same problem here. A non-hacky solution would be appreciated ..

lugler commented 6 years ago

Same problem here.

gconesa commented 6 years ago

Same problem here.

wcustodio commented 6 years ago

Same problem. Any solution?

For a while I disabled WKWebView and use UIWebView in config.xml: <preference name="CordovaWebViewEngine" value="CDVUIWebViewEngine" />

But it's not recommended by Ionic team.

desmeit commented 5 years ago

Still not working. It crashs at my splash screen. Is there a solution?

JoabChua commented 5 years ago

Still not working too. Using ionic4, launching into my ipad, ios9.0.

dhayaljaswantgit commented 5 years ago

use following commands to fix that issue :

ionic cordova plugin rm cordova-plugin-background-mode ionic cordova plugin add https://github.com/iowayankee/cordova-plugin-background-mode.git

kapilSoni101 commented 4 years ago

@wcustodio: thanks a lot sir its worked me.