File tree Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Original file line number Diff line number Diff line change 10
10
using Foundation ;
11
11
using UIKit ;
12
12
using System . Threading . Tasks ;
13
+ using CoreFoundation ;
13
14
14
15
namespace Parse {
15
16
public partial class ParseInstallation : ParseObject {
@@ -54,16 +55,39 @@ public void SetDeviceTokenFromData(NSData deviceToken) {
54
55
public int Badge {
55
56
get {
56
57
if ( CurrentInstallationController . IsCurrent ( this ) ) {
57
- SetProperty < int > ( ( int ) UIApplication . SharedApplication . ApplicationIconBadgeNumber ) ;
58
+ RunOnUIQueue ( ( ) =>
59
+ SetProperty < int > ( ( int ) UIApplication . SharedApplication . ApplicationIconBadgeNumber )
60
+ ) ;
58
61
}
59
62
return GetProperty < int > ( ) ;
60
63
}
61
64
set {
62
65
int badge = value ;
63
66
// Set the UI, too
64
- UIApplication . SharedApplication . ApplicationIconBadgeNumber = ( nint ) badge ;
67
+ RunOnUIQueue ( ( ) => {
68
+ UIApplication . SharedApplication . ApplicationIconBadgeNumber = ( nint ) badge ;
69
+ } ) ;
65
70
SetProperty < int > ( badge ) ;
66
71
}
67
72
}
73
+
74
+ /// <summary>
75
+ /// Runs (synchronously) the on user interface queue.
76
+ ///
77
+ /// Note that this could cause deadlocks, if the main thread is waiting on
78
+ /// the background thread we're calling this from.
79
+ ///
80
+ /// However, Xamarin's native bindings always threw exceptions when calling
81
+ /// into UIKit code from a background thread, so this at least helps us in
82
+ /// some deadlock scenarios.
83
+ /// </summary>
84
+ /// <param name="action">Action.</param>
85
+ private static void RunOnUIQueue ( Action action ) {
86
+ if ( NSThread . IsMain ) {
87
+ action ( ) ;
88
+ } else {
89
+ DispatchQueue . MainQueue . DispatchSync ( action ) ;
90
+ }
91
+ }
68
92
}
69
- }
93
+ }
You can’t perform that action at this time.
0 commit comments