美文网首页
iOS 用户注册之后只显示一次引导图 ps:为什么不能接收到通知

iOS 用户注册之后只显示一次引导图 ps:为什么不能接收到通知

作者: PINKAPINKA | 来源:发表于2017-04-19 16:53 被阅读40次

想要做一个如下图的需求 用户第一次注册之后显示

我的思路是: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];

}];

相关文章

网友评论

      本文标题:iOS 用户注册之后只显示一次引导图 ps:为什么不能接收到通知

      本文链接:https://www.haomeiwen.com/subject/jtdhzttx.html