通知的使用方法二,可执行App delegate中的某些方法
IOS设置完定位后回到APP中后要自动做某些操作的方法,使用通知
//宏定义一个名称
#define EnterForeground @"UIApplicationDidBecomeActiveNotification"
//发起通知
[[NSNotificationCenter defaultCenter]postNotificationName:EnterForeground object:nil];
//注册通知(name是通知的名称,这里使用的是UIApplicationDidBecomeActiveNotification,意思是应用程序为当前有效的,就是显示在用户面前时促发)
UIApplication *application = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationDidBecomeActive:) name:EnterForeground object:application];
//接收通知执行的方法
- (void)applicationDidBecomeActive:(NSNotification *)notification {
if ([CLLocationManager locationServicesEnabled]&&[_shopParameter.islocate isEqualToString: @"false"]&&([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse||[CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways)&&[self.isArticle isEqualToString:@"0"]&&[_shopOrderFlag isEqualToString:@"1"]) {
//如果定位可用,用户没有拒绝使用,islocate为false,用户选择的是趣处,且选中距离最近 则去定位,定位后刷新数据
[self createLocationManager];
}
}