Tag: nsnotificationcenter

iOS检测系统音量水平变化。 私人API或不? AVSystemController_SystemVolumeDidChangeNotification

可以听AVSystemController_SystemVolumeDidChangeNotification NSNotification(在App Store审查过程中)是否使用私有API? 在我的应用程序中,我需要显示和更新当前音量。 在按下硬件音量button和MPVolumeView滑块中的音量更改之后,音量指示符应该更新。 我已经search了解决scheme如何获得硬件音量button按通知或事件,并已find一些解决scheme。 例如, iPhone检测音量键按下。 和 如何在iOS上获得音量级别和音量更改通知? 我喜欢听NSNotificationCenter的解决scheme,似乎最简单和明确的解决scheme是听AVSystemController_SystemVolumeDidChangeNotification (它工作正常) 但有一件重要的事情我想知道。 此通知名称不在任何官方Apple文档中出现,并且有关是否将此通知用法视为“使用私有API”的讨论。 据我所知,使用私有API与调用私有方法连接。 这就是为什么使用这个通知密钥不能被视为私人API使用(因为实际上我们正在使用通知名称作为NSString)。 也许有人知道这是肯定的,或者有AVSystemController_SystemVolumeDidChangeNotification使用经验和应用程序被提交/拒绝? 非常感谢您的任何信息!

NotificationCenter swift3无法观察post

我有3个通知: NotificationCenter.default.post(name:NSNotification.Name("Notification1"), object: nil) NotificationCenter.default.post(name:NSNotification.Name("Notification2"), object: nil) NotificationCenter.default.post(name:NSNotification.Name("Notification3"), object: nil) 我在视图控制器中为每个post分配一个不同的观察者 第一个 : NotificationCenter.default.addObserver(forName:NSNotification.Name("Notification1"), object: nil, queue: nil, using: updateUx) 第二种 : NotificationCenter.default.addObserver(forName:NSNotification.Name("Notification2"), object: nil, queue: nil, using: updateUx) 第三 : NotificationCenter.default.addObserver(forName:NSNotification.Name("Notification3"), object: nil, queue: nil, using: updateUx) updateUx函数只包含一个通知的打印。 我只有我的第一个通知,我不能赶上另外两个,我不知道为什么。

NSNotificationCenter:不是自我的addObserver

这是一个问题: 在第二个视图加载之前,一个View Controller能否将另一个View Controller作为Observer添加到defaultCenter中? 我有一个模型类创build一个NSURLSession ,抓取一些数据,build立一个数组,并发送通知它已经完成(以及一个指向数组的指针)。 我的应用程序加载了一个实例化模型的Map View,调用创build该数组的方法,侦听通知,并使用该数组删除引脚。 我有一个表格视图选项卡,我想加载使用由地图build立的数组。 我的地图视图可以在加载表视图之前将我的表视图控制器添加为观察者? 就像是: [[NSNotificationCenter defaultCenter] addObserver: TableViewController … 感谢您的任何见解。 我正在考虑这个问题。 – – – – – – – – -编辑 – – – – – – – – – – viewDidLoad来自MapViewController: – (void)viewDidLoad { [super viewDidLoad]; _mapView.delegate = self; _model = [[WikiModel alloc] init]; _lastArticleUpdateLocation = [[CLLocation alloc] […]

点击像所有的视图应该显示如同C

当我selectThrowback – >如果我点击像button那样的描述发生像button改变不像和“像计数= 1099”增加。 如果我按回我希望这不像显示旁边显示在一个标签,并再次select回滚button应该显示不像和像计数应为1100.请帮助我如何实现这一目标? //DetailOfUser.m #impot"DetailsOfStories.h" @interface DetailOfUser ()<UITableViewDelegate,UITableViewDataSource> { NSMutableArray *arrayAboutList; DetailsOfStories *viewController; } – (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"cell"; UILabel *title=[(UILabel *)cell viewWithTag:2]; title.text=[NSString stringWithFormat:@"%@", [arrayAboutList[indexPath.row] valueForKey:@"title"]]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"DetailsOfStories"]; viewController.descriptionList = [arrayAboutList[indexPath.row] mutableCopy]; [self.navigationController pushViewController:viewController animated:YES]; } @end //DetailsOfStories.m […]

iOS:为什么我们的应用程序有时不会显示在通知中心?

关于这个问题有三种情况。 在开发过程中,我可以重新启动iPhone并重新安装应用程序来解决这个问题。 起初,这个问题经常发生在越狱iPhone中,所以我们认为configuration文件可能有问题。 但现在,越来越多的用户抱怨(无法接受推送),谁使用正常的iPhone(不越狱),并从App Store下载我们的应用程序。 所以,我很困惑,有点担心,为什么我们的应用程序不显示在通知中心,以及如何帮助用户解决问题。 非常感谢。 更新1: 即使我们的应用程序注册成功,并获得deviceToken – (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 这个问题可能会发生。

Swift 2 addObserver特定的textField与对象参数

据我了解, addObserver方法的object参数是你想要接收通知的对象。 大多数时候,我认为它nil (我认为这是因为指定types的通知是从所有对象中获取的)。 在我的特殊情况下,我在屏幕的顶部和屏幕的底部有一个文本字段,我希望只有当用户点击底部文本字段,而不是顶部的时候,视图才会向上移动。 所以我在viewWillAppear调用下面的方法 func subscribeToKeyboardNotifications() { NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: self.bottomTextField) NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: self.bottomTextField) } keyboardWillShow:和keyboardWillHide:select器调用方法来重新定位视图的框架。 我试图离开object参数nil但是会从两个文本字段接收通知。 我尝试设置object参数self.bottomTextField (如上所示),但不接收来自任何文本字段的通知。 我的问题是双重的。 首先,我正确理解addObserver方法(特别是object参数),其次,为什么不从self.bottomTextField注册通知。 谢谢! 解决scheme:我知道这不是我所问的确切问题的解决scheme,但是我最终做了什么以使视图向上移动,只需点击底部的文本字段即可: func subscribeToKeyboardNotifications() { NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil) } 然后在keyboardWillShow:方法中我有: func keyboardWillShow(notification: NSNotification) { […]

ios通知“死”的对象

我有一些UIViews进入视图,然后走出看法和未使用。 不过,我相信其中一些人在收到通知后,即使在他们离开后也会造成问题。 在UIView“父”容器上: if(self._content != nil && [self._content respondsToSelector:@selector(presentMe:)]) { [self._content presentMe:NO]; } 在UIView“孩子”: [[NSNotificationCenter defaultCenter] <– EXC_BAD_ACCESS (code=1, address=0x70000008 postNotificationName:PRESENTING object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:prepareToEnter], PRESENTING, nil]]; 一切工作都是第一次,但如果我第二次启动相同的视图,我会得到一个EXC_BAD_ACCESS。 这不是说有什么缺失吗? 仅供参考,这是所有在ARC – Xcode 4.3.2

如果显示UIAlertView,是否在iOS上有通知?

想知道是否有通知可用,如果UIAlertViewpopup? 背景:我的应用程序在一段时间不活动后要求用户inputPIN码,但是如果屏幕上出现提示,我想阻止它。 我不想通过我的代码,并find所有警报和禁用PIN检查,而不是通知将是真棒。 NSNotification任何希望?

警告iOS / iPhone用户有关重复的NSNotification观察

这不是一个问题,而是警告其他人为了节省一些时间。 iOS 3 / iPhone OS 3上的NSNotificationCenter(我假设Mac OS X和iOS 4)具有以下行为: 如果您多次注册自己的具体通知,NSNotificationCenter将不会识别冗余,而是会向您发送尽可能多的通知给您,因为您已经注册了一个观察。 这几乎从来不是你想看到的行为,几乎总是偶然的。 例: 我希望我的视图控制器在接收到新数据时接收来自单例networking对象的通知: – (void) viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newDataArrived:) name:NewDataArrivedNotification object:[NetworkListener sharedNetworkListener]]; } 但早些时候,我已经把相同的东西在viewWillAppear : – (void) viewWillAppear { [super viewWillAppear]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newDataArrived:) name:NewDataArrivedNotification object:[NetworkListener sharedNetworkListener]]; } 请注意,这是完全相同的通知,parsing为相同的观察员,发件人和通知名称。 在这种情况下,如果我不删除其中一个addObserver调用,我会得到重复通知给我的视图控制器。 在multithreading环境中,这是一个受到伤害的世界。 相信我。 只要把它放在那里,以防其他人遇到这样的事情。

如何检查互联网连接在iOS?

我如何检查应用程序是否连接到互联网? 目前,我在我的appdelegate.m文件中使用这个代码 dispatch_queue_t connectivityThread = dispatch_queue_create("com.gm.kart.connectivity", NULL); dispatch_async(connectivityThread, ^{ while (true){ if([GMMConnectivity hasConnectivity]) NSLog(@"%@", @"connected"); else NSLog(@"Not connected"); usleep(10000000); } }); 当我点击我的loginbutton,我想检查互联网是否连接或不使用NSnotificationcenter ? 请帮帮我