Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

iOS 11 + xcode 9: warnings on calling UI methods from a background thread #1988

Closed
shankari opened this issue Oct 1, 2017 · 30 comments
Closed

Comments

@shankari
Copy link

shankari commented Oct 1, 2017

Expected Behaviour

There should be no warnings generated from the plugin

Actual Behaviour

Warnings about calling UI methods from the background thread - e.g.

"UI API called from background thread: -[UIApplication setApplicationIconBadgeNumber:] must be used from main thread only"

Reproduce Scenario (including but not limited to)

All the time

Steps to Reproduce

  • Add plugin to app that calls register
  • Run app

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

iOS 11

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Cordova CLI version and cordova platform version

cordova --version                                    # e.g. 6.0.0

Cordova CLI: 6.5.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
ios-deploy version: 1.9.0
ios-sim version: 5.0.6
OS: macOS Sierra
Node Version: v6.2.0
Xcode version: Xcode 9.0 Build version 9A235


$ ionic platform version ios
Installed platforms:
  android 6.1.2
  ios 4.3.1

Plugin version

$ ionic plugin list | grep plugin-push
phonegap-plugin-push 1.9.4 "PushPlugin"

But I checked the source code and the `setApplicationIconBadgeNumber`
method, for example, is called in a background thread even on the tip of
master.

```
[self.commandDelegate runInBackground:^ {
...
    if (clearBadgeArg == nil || ([clearBadgeArg isKindOfClass:[NSString class]] && [clearBadgeArg isEqualToString:@"false"]) || ![clearBadgeArg boolValue]) {
        NSLog(@"PushPlugin.register: setting badge to false");
        clearBadge = NO;
    } else {
        NSLog(@"PushPlugin.register: setting badge to true");
        clearBadge = YES;
        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    }
    NSLog(@"PushPlugin.register: clear badge is set to %d", clearBadge);
...
}];
```

Sample Push Data Payload

N/A

Sample Code that illustrates the problem

In www/js/app.js, .config

  $ionicCloudProvider.init({
    "core": {
      "app_id": "xxxxxxxx"
    },
    "push": {
      "sender_id": "xxxxxxxxxxx",
      "pluginConfig": {
        "ios": {
          "badge": true,
          "sound": true,
          "vibration": true,
          "clearBadge": true
        },
        "android": {
          "icon": "ic_question_answer",
          "iconColor": "#54DCC1",
          "clearNotifications": true
        }
      }
    }

Logs taken while reproducing problem

screen shot 2017-10-01 at 12 22 21 am

text_logs_warning_background_ui.log.gz

@Defcon0
Copy link

Defcon0 commented Oct 7, 2017

Same here:

2017-10-07 22:34:18.663028+0200 MyApp[2897:1262426] PushPlugin.register: setting badge to false
2017-10-07 22:34:18.663035+0200 MyApp[2897:1262426] PushPlugin.register: clear badge is set to 0
2017-10-07 22:34:18.663042+0200 MyApp[2897:1262426] PushPlugin.register: better button setup
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication registerUserNotificationSettings:]
PID: 2897, TID: 1262426, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21
Backtrace:
4   MyApp                      0x000000010096d910 __19-[PushPlugin init:]_block_invoke + 3540
5   libdispatch.dylib                   0x0000000100bdd49c _dispatch_call_block_and_release + 24
6   libdispatch.dylib                   0x0000000100bdd45c _dispatch_client_callout + 16
7   libdispatch.dylib                   0x0000000100be956c _dispatch_queue_override_invoke + 980
8   libdispatch.dylib                   0x0000000100beeb54 _dispatch_root_queue_drain + 616
9   libdispatch.dylib                   0x0000000100bee880 _dispatch_worker_thread3 + 136
10  libsystem_pthread.dylib             0x0000000182bdf130 _pthread_wqthread + 1268
11  libsystem_pthread.dylib             0x0000000182bdec30 start_wqthread + 4
2017-10-07 22:34:18.665691+0200 MyApp[2897:1262426] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication registerUserNotificationSettings:]
PID: 2897, TID: 1262426, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21
Backtrace:
4   MyApp                      0x000000010096d910 __19-[PushPlugin init:]_block_invoke + 3540
5   libdispatch.dylib                   0x0000000100bdd49c _dispatch_call_block_and_release + 24
6   libdispatch.dylib                   0x0000000100bdd45c _dispatch_client_callout + 16
7   libdispatch.dylib                   0x0000000100be956c _dispatch_queue_override_invoke + 980
8   libdispatch.dylib                   0x0000000100beeb54 _dispatch_root_queue_drain + 616
9   libdispatch.dylib                   0x0000000100bee880 _dispatch_worker_thread3 + 136
10  libsystem_pthread.dylib             0x0000000182bdf130 _pthread_wqthread + 1268
11  libsystem_pthread.dylib             0x0000000182bdec30 start_wqthread + 4
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication registerForRemoteNotifications]
PID: 2897, TID: 1262426, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21
Backtrace:
4   MyApp                      0x000000010096d95c __19-[PushPlugin init:]_block_invoke + 3616
5   libdispatch.dylib                   0x0000000100bdd49c _dispatch_call_block_and_release + 24
6   libdispatch.dylib                   0x0000000100bdd45c _dispatch_client_callout + 16
7   libdispatch.dylib                   0x0000000100be956c _dispatch_queue_override_invoke + 980
8   libdispatch.dylib                   0x0000000100beeb54 _dispatch_root_queue_drain + 616
9   libdispatch.dylib                   0x0000000100bee880 _dispatch_worker_thread3 + 136
10  libsystem_pthread.dylib             0x0000000182bdf130 _pthread_wqthread + 1268
11  libsystem_pthread.dylib             0x0000000182bdec30 start_wqthread + 4
2017-10-07 22:34:18.871525+0200 MyApp[2897:1262426] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication registerForRemoteNotifications]
PID: 2897, TID: 1262426, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21
Backtrace:
4   MyApp                      0x000000010096d95c __19-[PushPlugin init:]_block_invoke + 3616
5   libdispatch.dylib                   0x0000000100bdd49c _dispatch_call_block_and_release + 24
6   libdispatch.dylib                   0x0000000100bdd45c _dispatch_client_callout + 16
7   libdispatch.dylib                   0x0000000100be956c _dispatch_queue_override_invoke + 980
8   libdispatch.dylib                   0x0000000100beeb54 _dispatch_root_queue_drain + 616
9   libdispatch.dylib                   0x0000000100bee880 _dispatch_worker_thread3 + 136
10  libsystem_pthread.dylib             0x0000000182bdf130 _pthread_wqthread + 1268
11  libsystem_pthread.dylib             0x0000000182bdec30 start_wqthread + 4
2017-10-07 22:34:18.966368+0200 MyApp[2897:1262426] GCM Sender ID (null)
2017-10-07 22:34:18.966465+0200 MyApp[2897:1262426] Using APNS Notification
2017-10-07 22:34:18.992917+0200 MyApp[2897:1262312] Push Plugin register success: <removed ;-)>

macdonst added a commit that referenced this issue Oct 16, 2017
@macdonst
Copy link
Member

@shankari & @Defcon0 can you try the latest code from master? I believe it fixes the issue, at least it does for me.

@macdonst macdonst added this to the Release 2.1.0 milestone Oct 16, 2017
@macdonst
Copy link
Member

Currently fixed in master, soon to be in release 2.1.0.

@hsob
Copy link

hsob commented Oct 18, 2017


cli packages:

@ionic/cli-utils  : 1.13.1
ionic (Ionic CLI) : 3.13.1

global packages:

cordova (Cordova CLI) : 7.1.0 

local packages:

@ionic/app-scripts : 2.1.4
Cordova Platforms  : ios 4.4.0
Ionic Framework    : ionic-angular 3.5.3

System:

Android SDK Tools : 26.1.1
ios-deploy        : 1.9.2 
ios-sim           : 6.0.0 
Node              : v6.10.3
npm               : 3.10.10 
OS                : macOS Sierra
Xcode             : Xcode 9.0.1 Build version 9A1004 

phonegap-plugin-push version: 2.0.0

@ionic-native/push version: 4.3.2


When I build the app in Xcode Version 9.0.1 (9A1004), I get this:

screen shot 2017-10-18 at 4 50 59 pm

@macdonst
Copy link
Member

@hsob did you pull from master or grab the plugin from npm?

@hsob
Copy link

hsob commented Oct 18, 2017

from npm by executing these commands :

ionic cordova plugin add phonegap-plugin-push

npm install --save @ionic-native/push

@hsob
Copy link

hsob commented Oct 18, 2017

npm install --save @ionic-native/push

@hsob
Copy link

hsob commented Oct 18, 2017

screen shot 2017-10-18 at 4 59 12 pm

@jcesarmobile
Copy link
Collaborator

so, read latest comments, it's fixed on master, but not released yet. Will be on the next release (2.1.0)

@hsob
Copy link

hsob commented Oct 18, 2017

Cool, so when do you expect to update it?

thanks,

@macdonst
Copy link
Member

@hsob by the end of the week

@macdonst macdonst removed the staging label Oct 20, 2017
@unostella
Copy link

unostella commented Oct 20, 2017

Hi @macdonst,

Thanks for releasing 2.1.0, however there is some issue when trying to install on latest Ionic and Cordova. Please see attached screen. I am on [email protected], [email protected], [email protected]

screen shot 2017-10-20 at 21 04 26

image

@macdonst
Copy link
Member

@unostella do you have cocoapods installed?

@unostella
Copy link

@macdonst Hi Simon, I've got latest [email protected]. Below is what I am seeing when I try to build ios despite getting error above (on installing [email protected])

image

@Defcon0
Copy link

Defcon0 commented Oct 21, 2017

Have had the same issue here. Calling "pod repo update" after updating cocoapods did the trick :-)

@Defcon0
Copy link

Defcon0 commented Oct 21, 2017

Unfortunately, I now have another problem:

Plugin doesn't support this project's cordova version. cordova: 7.0.1, failed version requirement: >=7.1.0

But indeed I have cordova 7.1.0 (cordova -v shows that). Do I have to do something else to get it working?

@unostella
Copy link

unostella commented Oct 21, 2017

@macdonst @Defcon0 It works for me, I forgot to add Firebase as I was using v1.10.5 that didn't require it https://ionicframework.com/docs/native/firebase/
I also used latest [email protected] (sudo gem install cocoapods --pre), although this probably doesn't make any difference
It compiles fine on .xcodeproj instead of .xcworkspace

@Defcon0
Copy link

Defcon0 commented Oct 21, 2017

@macdonst: ??? Should we now don‘t use the workspace anymore?

@hsob
Copy link

hsob commented Oct 23, 2017

I succeeded to add the new version of the plugin but i got theses errors when i built in Xcode:

screen shot 2017-10-23 at 10 21 35 am

screen shot 2017-10-22 at 11 06 51 am

@hsob
Copy link

hsob commented Oct 23, 2017

I can't explain why:

  • I receive notifications in background mode (when i close the app)
  • I don't receive notifications in foreground mode (the app is open)

The plugin works as expected in version 1.8.x, but in versions 2.x.x I have this strange feature.

I didn't add "GoogleService-Info.plist" in my project, is it the cause?

Can you please help me?

Thanks,

@Defcon0
Copy link

Defcon0 commented Oct 26, 2017

@hsob I guess you need to create a new issue for that :-)

@mattprudente
Copy link

Has v2.1.0 been released? I've just installed via cordova plugin add phonegap-plugin-push and I have v2.0.0.

@alessio-gaggii
Copy link

alessio-gaggii commented Jan 20, 2018

I'm using the version 2.1.2 but I'm having the same issue with Xcode [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];.
I no longer receive Push notifications in background or foreground, but the registration is successful in the logs (everything works fine with the version 1.8.2 and Ionic 2). I have also installed the latest version of cocoapods, but Xcode always shows this issue in Runtime.

System information:
cordova (Cordova CLI) : 8.0.0
ionic/app-scripts : 3.1.7
Cordova Platforms : android 6.0.0 ios 4.5.0
Ionic Framework : ionic-angular 3.9.2

Screen shot attached
xcode_push_runtime

I'm building selecting the file .xcworkspace because the build with the file .xcodeproj fails.
Does anyone know how to resolve this issue? @macdonst should I open a new issue?

@tattivitorino
Copy link

tattivitorino commented Feb 26, 2018

I have a question.. Do any of you think Apple would reject if we submit the app with these warnings?

Main Thread Checker: UI API called on a background thread: -[UIApplication registerUserNotificationSettings:]
Main Thread Checker: UI API called on a background thread: -[UIApplication registerForRemoteNotifications]

I'm using both Local and Push Plugins

<plugin name="phonegap-plugin-push" spec="^1.9.0" />
<plugin name="de.appplant.cordova.plugin.local-notification" spec="~0.8.5" />

@shankari
Copy link
Author

@tattivitorino I haven't upgraded the plugin yet (I am a little busy and don't have the time to do the re-tests), and my updates haven't been rejected yet!

@tattivitorino
Copy link

@shankari, good to hear that! I am about to submit and I really dont have time to upgrade and test this right now! thank you so much!

@richardshergold
Copy link

@tattivitorino did your app get accepted ok despite those warnings?

@tattivitorino
Copy link

hi @richardshergold I haven't submitted yet. My client had a few problems and we're still waiting!

@djmuhlestein
Copy link

I have plugin version 2.2.2.
Still getting the same warnings at runtime though. I'm calling PushNotification.init inside my device ready callback. Is that not right? I'm unclear as to why this bug is closed if the issue still exists.

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests