想要做一个如下图的需求 用户第一次注册之后显示
我的思路是:1.在用户注册成功的block 里面发送通知 2.在初始化页面注册通知监听
[RequestUtilscommonPostMultipartFormDataUtils:self.parmsForAPIbURL:urlbAnimatedViewController:selfconstructingBodyWithBlock:^(id_NonnullformData) {
[MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];
[formDataappendPartWithFileData:UIImageJPEGRepresentation(self.avatarImageView.image,0.5)name:@"photo"fileName:fileNamemimeType:mimeType];
}success:^(id_Nullabledict) {
[MBProgressHUDhideHUDForView:self.viewanimated:YES];
[selfsaveUserDefaultFormRequestAPI:dict];
NSLog(@"rongyun token Test%@",dict);
//发送红包通知
[[NSNotificationCenterdefaultCenter]postNotificationName:@"FIRSTREGISTE"object:nil];
AppDelegate*appDelegate = (AppDelegate*)[[UIApplicationsharedApplication]delegate];
[self.viewremoveFromSuperview];
[appDelegateloginSuccess];
}failure:^(id_Nullablefailure) {
[MBProgressHUDhideHUDForView:self.viewanimated:YES];
}];
-(void)viewWillAppear:(BOOL)animated{
[superviewWillAppear:animated];
//add红包通知
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(handleFirstRedPacket)name:@"FIRSTREGISTE"object:nil];
}
-(void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@"FIRSTREGISTE"object:nil];
}
但是这样是不能够接收到通知的!!!!!!因为不在一个线程里面,注册成功block 里买呢发送通知 那是一个新的线程,而接受却是在主线程里面,所以说发送和接受必须在同一个线程,而且最好都在主线程,利用gcd 来从子线程回到主线程,所以改代码如下:
[RequestUtilscommonPostMultipartFormDataUtils:self.parmsForAPIbURL:urlbAnimatedViewController:selfconstructingBodyWithBlock:^(id_NonnullformData) {
[MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];
[formDataappendPartWithFileData:UIImageJPEGRepresentation(self.avatarImageView.image,0.5)name:@"photo"fileName:fileNamemimeType:mimeType];
}success:^(id_Nullabledict) {
[MBProgressHUDhideHUDForView:self.viewanimated:YES];
[selfsaveUserDefaultFormRequestAPI:dict];
NSLog(@"rongyun token Test%@",dict);
dispatch_async(dispatch_get_main_queue(), ^{
//发送红包通知
[[NSNotificationCenterdefaultCenter]postNotificationName:@"FIRSTREGISTE"object:nil];
});
AppDelegate*appDelegate = (AppDelegate*)[[UIApplicationsharedApplication]delegate];
[self.viewremoveFromSuperview];
[appDelegateloginSuccess];
}failure:^(id_Nullablefailure) {
[MBProgressHUDhideHUDForView:self.viewanimated:YES];
}];