katzer / cordova-plugin-background-mode

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

No working from iOS 12.2 #419

Open gondp opened 5 years ago

gondp commented 5 years ago

After updating to iOS 12.2 the application ends just run. If I delete the plugin it works correctly

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key _alwaysRunsAtForegroundPriority.'

Baadier-Sydow commented 5 years ago

I'm experiencing this too after testing the application on 12.2

mciekurs2 commented 5 years ago

Can confirm, having the same problem.

BuddyLReno commented 5 years ago

it looks like it's because the plugin is using a private api which is no longer allowed: https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/293

T3chTobi commented 5 years ago

is there a solution to use background mode in iOS 12.2?

BuddyLReno commented 5 years ago

@CodingAnonymous As of right now, no. My team is now actively moving away from Ionic and Cordova because of this issue. We've been meaning to start going fully native for awhile, but this issue cemented our path.

mlynch commented 5 years ago

@BuddyLReno The issue on Ionic’s end has been fixed in latest webview plugin. Also, We don’t maintain this background plugin

Hao-Axon commented 5 years ago

We are experiencing the same problem. We cannot just let our app crash on the new version of the system. Please let us know if this issue can be fixed soon (@katzer ). Or any possible solutions are welcome.

BuddyLReno commented 5 years ago

@mlynch yes but the solution doesn't restore original functionality.

Without the background mode working as before, we're unable to save the progress through a users audio. Our app plays 40+ minute podcasts so it's important so save the progress about every ten seconds while the phone is locked.

iowayankee commented 5 years ago

Same problem. To fix I went to the plugin in Xcode. Removing lines APPBackgroundMode.m:266 & 267: [obj setValue:[NSNumber numberWithBool:YES] <--- remove! forKey:[APPBackgroundMode wkProperty]]; <--- remove!

I was able to get a build working. Haven't tested beyond that.

Hao-Axon commented 5 years ago

@iowayankee Can the plugin still work properly after your change?

KinG-InFeT commented 5 years ago

Can confirm, having the same problem.

wynngd commented 5 years ago

Encountered the same issue.Thanks @iowayankee! Your fix works. However, I still need to check the impact of the fix in background mode...

sergey-mohov commented 5 years ago

Try in file src\ios\APPBackgroundMode.m replace following lines

+ (NSString*) wkProperty
{
    NSString* str = @"X2Fsd2F5c1J1bnNBdEZvcmVncm91bmRQcmlvcml0eQ==";
    NSData* data  = [[NSData alloc] initWithBase64EncodedString:str options:0];

    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}

with

+ (NSString*) wkProperty
{
    NSString* str = @"YWx3YXlzUnVuc0F0Rm9yZWdyb3VuZFByaW9yaXR5";
    NSData* data  = [[NSData alloc] initWithBase64EncodedString:str options:0];

    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
edwardbrosens commented 5 years ago

Try in file src\ios\APPBackgroundMode.m replace following lines

+ (NSString*) wkProperty
{
    NSString* str = @"X2Fsd2F5c1J1bnNBdEZvcmVncm91bmRQcmlvcml0eQ==";
    NSData* data  = [[NSData alloc] initWithBase64EncodedString:str options:0];

    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}

with

+ (NSString*) wkProperty
{
    NSString* str = @"YWx3YXlzUnVuc0F0Rm9yZWdyb3VuZFByaW9yaXR5";
    NSData* data  = [[NSData alloc] initWithBase64EncodedString:str options:0];

    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}

This actually worked for me.

Basically what you did was changing the base64 encoded string from: _alwaysRunsAtForegroundPriority to alwaysRunsAtForegroundPriority

AthiraWD commented 5 years ago

Same problem. To fix I went to the plugin in Xcode. Removing lines APPBackgroundMode.m:266 & 267: [obj setValue:[NSNumber numberWithBool:YES] <--- remove! forKey:[APPBackgroundMode wkProperty]]; <--- remove!

I was able to get a build working. Haven't tested beyond that.

Wow! works good

ghenry22 commented 5 years ago

@BuddyLReno I submitted a PR to the Ionic Webview repository that should restore the background functionality, is backward compatible and has no issues with app store submissions that I have seen as long as you have valid background capability set and actual valid activity when in background (as it was previously). Give it a try if you like.

donkeytronkilla commented 5 years ago

@ghenry22 can you link your PR?

BorntraegerMarc commented 5 years ago

link for @ghenry22's PR https://github.com/ionic-team/cordova-plugin-ionic-webview/pull/343

silvanavlima commented 5 years ago

Can someone confirm if it worked?

silvanavlima commented 5 years ago

@gpartida It worked?

donkeytronkilla commented 5 years ago

@silvanavlima it passed our QA on testflight, we havent submitted the app for public release but we should be doing this soon.

silvanavlima commented 5 years ago

@gpartida but the background mode is working as before? or lost functionality?

donkeytronkilla commented 5 years ago

For my use case it works as before. I think this fix is about using the new name for an API which is still private not tapping into a more legit way to handle background functionality, so this is still bad and could easily just disappear one day, but it fixes my app from being completely broken today.

silvanavlima commented 5 years ago

@BuddyLReno the background mode plugin does not work? my audios stop when it's in the background. Is it the same with you?

KinG-InFeT commented 5 years ago

+1

joaowebdec commented 5 years ago

+1

rodrigovrm commented 5 years ago

I did what seems to be quickest way to get it working.

It just doesn't make sense that it also works on iOS 11.4. I tested in a simulator. Does anyone know why it works in earlier versions of iOS?

sts-ryan-holton commented 5 years ago

Has anyone got a fix for this not working on iOS 12?

GloomyStranger commented 5 years ago

@BuddyLReno The issue on Ionic’s end has been fixed in latest webview plugin. Also, We don’t maintain this background plugin

So maybe you have suggestion how we can make app runs backgroud

IwonGunawan commented 5 years ago

Same problem. To fix I went to the plugin in Xcode. Removing lines APPBackgroundMode.m:266 & 267: [obj setValue:[NSNumber numberWithBool:YES] <--- remove! forKey:[APPBackgroundMode wkProperty]]; <--- remove!

I was able to get a build working. Haven't tested beyond that.

thank @iowayankee , your save my time. this worked for me.

kapilSoni101 commented 5 years ago

@iowayankee sir tried but got same error again ?

16am commented 5 years ago

None of the solutions worked for me. I had to uninstall backgroundMode completely as, nor condition based on this.platform.is('android') works.

ZaLiTHkA commented 5 years ago

@BuddyLReno The issue on Ionic’s end has been fixed in latest webview plugin. Also, We don’t maintain this background plugin

@mlynch I understand that nobody is maintaining this plugin anymore, but I've tried with both cordova-plugin-ionic-webview 2.5.1 (because we actually still need to support iOS 10 with our app) as well as the latest 4.1.1 release, but I still can't get this plugin to work on our iOS 12.3 iPad. Not sure about 12.2 because I don't have any devices with that version, but it does still work on our iOS 12.0 iPad.

From your message above, I'm assuming the latest version of cordova-plugin-background-mode should work if I use a release of cordova-plugin-ionic-webview that provides the required API methods. Or am I missing something here? There are so many forks of this plugin, I'm honestly not sure where to start..


edit: alrighty, got it working with the latest of both the 2.x and 4.x releases of cordova-ionic-webview by switching over to @iowayankee's fork over at https://github.com/iowayankee/cordova-plugin-background-mode

I'm happy, my boss is happy, and life is good again. (:

kapilSoni101 commented 5 years ago

hi team anybody fixed above issue in iOS 12.2?

edento commented 5 years ago

@ZaLiTHkA Have you actually tested the background activity? this fix fixes the app crash, but all http requests that are triggered by location change (which is working properly) when the app is in the background fail:

{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":null,"ok":false,"name":"HttpErrorResponse","message":"Http failure response for (unknown url): 0 Unknown Error","error":{"isTrusted":true}}

I have tried updating cordova-plugin-ionic-webview to 2.5.1 and it leads to same error. Same code works for iOS 12.1.

Any leads?

ZaLiTHkA commented 5 years ago

@edento, if you have a look at the edit to my previous message, you might notice I've actually switched to a fork of a fork of this project..

this is just one of the unfortunate side-effects of dealing with Cordova plugins in general, most of them tend to either get ignored for long periods of time or abandoned completely, so when one dev with good intentions forks the project to fix something, their PR never gets back to the original. and so this one has (currently) 752 forks. O.o

that said, I'm not sure about handling things like HTTP calls while the app is in the background. in our case, we have a socket connection with observables that give me data when the data source updates, so it's not an action I need to explicitly call. I do know that the webview engine does limit the frequency of function calls made in background mode, but I'm not sure if it affects them in any other ways.


if you're trying to explicitly fetch data from a remote source while your app is in the background, perhaps you might benefit from moving that "fetch" logic into a service worker? haven't played with them much myself, but as I understand these are specifically designed to operate "in the background" behind the main app thread, so they aren't restricted by the same means.

beyond that, I'm not really sure what else to suggest.

edento commented 5 years ago

@ZaLiTHkA You're right, I missed the fork link. Anyway I tested it and unfortunately its not working for my case. I want to make a post request with the new user location to do some server calculation, but the request never makes it to the server =\

Thank you for the response anyway :)

edento commented 5 years ago

@ZaLiTHkA well, eventually changing the HTTP package resolved this issue. Changed angulars package HttpClient (@angular/common/http) to @ionic-native/http/ngx.

kapilSoni101 commented 5 years ago

@edento: sir what is realtion of above issue with HttpClient plz explain me.

@ZaLiTHkA: sir are u fixed issue after change version of Crdova-plugin-ionic-webview

ZaLiTHkA commented 5 years ago

@edento: sir what is realtion of above issue with HttpClient plz explain me.

I don't think it relates to this issue specifically, that's just the module Eden was trying to use while their app was in background mode..

@ZaLiTHkA: sir are u fixed issue after change version of Crdova-plugin-ionic-webview

nope, not by changing the webview plugin (doing that made no difference), I "fixed" mine by changing to this fork of the background mode plugin.


note: I see there was actually an update to this project recently, so have you tried using version 0.7.3 yet?

kapilSoni101 commented 5 years ago

@ZaLiTHkA : ok sir I tried above mentioned fork and tell me one more thing sir why its not working in IOS 10 version also.

kapilSoni101 commented 5 years ago

@iowayankee and @sergey-mohov : sir i tried ur solution but not worked for me?