RJBadgeKit
RJBadgeKit copied to clipboard
dispatch_queue_async_rjbk went wrong in viewDidLoad
In application: didFinishLaunchingWithOptions:
UITabBarController *tabVC = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
UITabBarItem *mineItem = tabVC.tabBar.items.lastObject;
NSString *minePath = @"root.mine";
mineItem.badgeOffset = CGPointMake(5, 5);
[self.badgeController observePath:minePath badgeView:mineItem block:^(id _Nullable observer, NSDictionary<NSString *,id> * _Nonnull info) {
NSLog(@"%@",info);
}];
NSString *mineMessagePath = @"root.mine.message";
[RJBadgeController setBadgeForKeyPath:mineMessagePath count:9];
In MineViewController viewDidLoad
NSString *mineMessagePath = @"root.mine.message";
[self.badgeController observePath:mineMessagePath badgeView:self.navigationItem.leftBarButtonItem block:^(id _Nullable observer, NSDictionary<NSString *,id> * _Nonnull info) {
NSLog(@"%@",info);
}];
leftBarButtonItem in MineViewController did not show the badge, caused by dispatch_queue_async_rjbk did not execute the code!
Use
dispatch_async(dispatch_get_main_queue(), ^{
});
instead.
iOS 11.3.1, Xcode9.4 ,iPhone8