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

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

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

}];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户感兴趣的那么通过通知...
    莫离_焱阅读 11,609评论 1 8
  • 转至元数据结尾创建: 董潇伟,最新修改于: 十二月 23, 2016 转至元数据起始第一章:isa和Class一....
    40c0490e5268阅读 5,883评论 0 9
  • 最近10多年发展最快的行业中,IT行业应该是首当其冲了,极大了改变了我们的工作与生活的方式,从衣食住行、沟通交流、...
    许鹏辉阅读 3,496评论 0 0
  • 1
    sean11阅读 1,468评论 0 0
  • 打卡第二天。更新文章:(再见)。字数1452 12月12,我驾着车,在口岸接上我哥,然后从广深高速上走。 无数次,...
    静谧而已阅读 1,576评论 0 0

友情链接更多精彩内容