How To Get UIAccessibilityVoiceOverStatusChanged Notification - iphone

How to implement to get UIAccessibilityVoiceOverStatusChanged Notification?
I tried like below but nothing happens :
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:#selector(notified:) name:UIAccessibilityVoiceOverStatusChanged object:self];

That looks reasonable, except maybe object:self should be object:nil?
The other thing is to be sure your signature is correct:
- (void)voiceOverStatusChanged: (NSNotification *)notification;

I think you might try adding the observer in the awakeFromNib method with the right selector signature.
Something like this will work
- (void)awakeFromNib {
[super awakeFromNib];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(voiceOverChanged)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
[self voiceOverChanged];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIAccessibilityVoiceOverStatusChanged object:nil];
}
- (void)voiceOverChanged {
// Your actions here
}

you can get the UIAccessibilityVoiceOverStatusChanged Notification with the code
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(didChangeVoiceOverStatus:)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
}
- (void)didChangeVoiceOverStatus:(NSNotification *)notification {
if (UIAccessibilityIsVoiceOverRunning()) {
NSLog(#"VoiceOver is ON.");
} else {
NSLog(#"VoiceOver is OFF.");
}
}

Related

How to remove observer

I have an ARC enabled project
There are few observers added in viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(getSipNotification:) name:#"getSipNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(syncExtensionData:) name:#"syncExtensionData" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(showLocalNotification:) name:#"showLocalNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(outgoingCall:) name:#"outgoingCall" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playRingtone) name:#"playRingtone" object:nil];
I want to remove all observers so I added following line in viewDidUnload
[[NSNotificationCenter defaultCenter] removeObserver:self];
Now my question is, is this remove all observers?
If not how can do it?
UPDATE
If I want to remove a single observer how can do it?
Can you help me please.
Yes, It will remove all observers.
[[NSNotificationCenter defaultCenter] removeObserver:self];
And you can remove a particular observer like this...
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"syncExtensionData" object:nil];
In my application i used this notification :
for particular observer remove this way :
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(deviceRotatedFeedBackView:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void)deviceRotatedFeedBackView:(NSNotification*)notification
{
//right whetever you want
}
- (void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
may be it will helpful to you.
Yes it'll remove all the observers in your class.
You can use following to remove single observer:
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"getSipNotification" object:nil];
To remove individual observer.
viewDidUnload is deprecated in iOS6 and later, so Your observer never be removed from notification center in iOS6 and later. To remove single observer try
- (void)removeObserver:(id)notificationObserver name:(NSString *)notificationName object:(id)notificationSender

NSNotificationDefault Center called multiple times even removing observer before adding

I am adding observer to init method.And for the reason it will not call multiple times I am removing observer before adding it.Even then is is calling as many times as we load the View.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(updateStuff)
name:#"appDidBecomeActive"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(closeConnection)
name:#"appDidEnterBackground"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(orientationChanges:)
name:#"UIDeviceOrientationDidChangeNotification"
object:nil];
t=[[Theme alloc] init];
// Custom initialization
}
return self;
}
I have also tried it removing in updateStuff method
-(void)updateStuff
{
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
NSLog(#"Market Watch update stuff called $$$$$$$----------------------");
[self initNetworkCommunication];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
also tried removing here.
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"appDidBecomeActive" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"appDidEnterBackground" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"UIDeviceOrientationDidChangeNotification" object:nil];
}
also tried removing in viewWillDisappear It works fine but here adding observer to viewWillAppear not working.
When I lock the screen and unlock it this observer should call.As it is notified on appDidBecomeActive , and it is working like that. But when I pop back to previous viewController and push to current one and repeats the process of lock and unlock this observer fires two times.As number of times I pop view and push again to current View.Notifier fires number of times I pushed to the View.I know it is because of init method.Whenever view will load it adds an observer but doesn't removes observer.
What can I do other than that.
You have to remove observer in viewWillDisappear method.
-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
and remove from initWithNibName.
Try adding it to -awakeFromNib instead
Also, try removing the notification in a different manner. I don't have the code but you have to also give it the name of the notification, and you should only remove observer in dealloc

Getting NSNotification to Work?

I'm currently trying to get NSNotification to work but I'm having some trouble.
I have two (2) ViewControllers: A. MainViewController & B. LoginViewController.
In my MainViewController I have a logout button that will send a url to my LoginViewController to load it (without showing my loginView). However, it's not working.
In my MainViewController this is what I have:
- (IBAction)logout:(id)sender {
NSURL *logoutURL = [NSURL URLWithString:#"https://myurl.com/logout"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"logoutInitiated" object:logoutURL];
}
This is what I have in my LoginViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
WebView.delegate = self;
WebView.scalesPageToFit = YES;
WebView.multipleTouchEnabled = YES;
loadCount = 0;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(submitLogout) name:#"logoutInitiated" object:nil];
}
- (IBAction)submitLogout:(NSNotification*)notification {
[WebView stopLoading];
NSURL * signOutUrl = (NSURL*)[notification object];
[self loadURL:nil withURL:signOutUrl];
}
My problem is that when I press the logoutButton nothing happens. (Using NSLogs, I see that it never triggers the next step) Thank you!!!!
This is because your method name you are passing in selector is wrong. You need to add colon : at submitLogout: suffix
Use
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(submitLogout:) name:#"logoutInitiated" object:nil];
in place of
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(submitLogout) name:#"logoutInitiated" object:nil];
Hope it helps you.
When you add self as an observer, you use the selector "submitLogout" without a semicolon! But your method has an argument, so the correct selector would be #selector(submitLogout:).
Note the SEMICOLON
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(**submitLogout:**) name:#"logoutInitiated" object:nil];
- (IBAction)logout:(id)sender
{
NSURL *logoutURL = [NSURL URLWithString:#"https://myurl.com/logout"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"logoutInitiated" object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:logoutURL,#"RECEIVED_URL", nil]];
}
- (IBAction)submitLogout:(NSNotification*)notification
{
[WebView stopLoading];
NSURL * signOutUrl = (NSURL*)[notification objectForKey:#"RECEIVED_URL"];
[self loadURL:nil withURL:signOutUrl];
}

NSNotification not receiving in View Controller from appDelegate

hello i assign nsnotifiaction in app delegate.m's method and this method call eprox every 30sec, and i wants its notifcation in viewcontroller adn execute method,
here is my code of appdelegate .m
- (void)layoutAnimated:(BOOL)animated{
BOOL yy= self.bannerView.bannerLoaded;
if (yy==1){
self.iAdString=[NSMutableString stringWithString:#"1"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"BannerViewActionWillBegin" object:self];
}
else{
self.iAdString=[NSMutableString stringWithString:#"0"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"BannerViewActionDidFinish" object:self];
}
}
and in viewcontroller.m
//i defined in viewdidload method
- (void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willBeginBannerViewActionNotification:) name:#"BannerViewActionWillBegin "object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didFinishBannerViewActionNotification:) name:#"BannerViewActionDidFinish" object:nil];
}
its method are..
- (void)willBeginBannerViewActionNotification:(NSNotification *)notification{
[self.view addSubview:self.app.bannerView];
NSLog(#"come");
}
- (void)didFinishBannerViewActionNotification:(NSNotification *)notification {
NSLog(#"come");
[self.app.bannerView removeFromSuperview];
}
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
I have not getting response of excessing method while method read in appdelegate file.
Please help me.
You have a typo error.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willBeginBannerViewActionNotification:) name:#"BannerViewActionWillBegin "object:nil];
//Your error here-------------------------------------------------------------------------------------------------------------------------------------^
You have put a space there.
SideNote: For all notification names, you should/can create a separate file and put all your notification names as constants strings.
const NSString *kBannerViewActionWillBegin=#"BannerViewActionWillBegin";
this will be easier to change the value and no such typo will happen.
From your code what I get is except for the notification name's all other stuff is fine, did you check whether the notification gets fired. Try keeping break points at the notification firing line.

NSnotifiaction doubts

I have a UISwitchcontroller in my setting page to change the image in main page. So I put a notification from setting page to main page. But only one notification I active every time, my setting page switch code look like this:
-(IBAction)_clickswitchlowlight:(id)sender
{
if(switchControll.on){
[switchControll setOn:YES animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlighton object:nil];
}
else{
[switchControll setOn:NO animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlightoff object:nil];
}
}
In my main page.h..I write this code:
extern NSString * const NOTIF_lowlighton;
extern NSString * const NOTIF_lowlightoff;
In .m above the implementation of main page I write this:
NSString * const NOTIF_lowlighton = #"lowlighton";
NSString * const NOTIF_lowlightoff = #"lowlightoff";
In viewwillappear I write this code:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(clicklowlighton:) name:#"lowlighton" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(clicklowlightoff:) name:#"lowlightoff" object:nil];
}
Then this code for changing the image:
- (void)clicklowlighton:(NSNotification *)notif
{
[[self multiPageView] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"bgipad"]]];
}
- (void)clicklowlightoff:(NSNotification *)notif
{
[[self multiPageView] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"bglowlight#2x"]]];
}
I only get the clicklowlightoff notification, I didn't get the first notification...any missing in my code?
bind your function to event: UIControlEventValueChanged to this function
-(IBAction)_clickswitchlowlight:(id)sender
{
if(switchControll.on){
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlighton object:nil];
}
else{
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlightoff object:nil];
}
}