[NSConcreteNotification isReachable]: unrecognized selector sent to instance - ios5

I'm trying to get ASIReachability to work in my app which works when the connection isn't there but when the connection exists it give the following error:
2013-04-08 12:26:20.501 Your Llanelli Companion[1576:207] -[NSConcreteNotification isReachable]: unrecognized selector sent to instance 0x7d84d30
I can't seem to remedy this and it's beginning to bug me.
.m file:
- (void) CheckIfAInternetConnectionExists
{
Reachability *reach = [[Reachability reachabilityWithHostName:#"http://176.31.101.181:8020/listen.pls"]retain ];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
[reach startNotifier];
}
- (void) reachabilityChanged:(Reachability *)reach {
if ([reach isReachable ]) {
NSLog(#"connection");
ServerFound = YES;
[self PrepareStream];
} else{
NSLog(#"no connection");
ServerFound = NO;
[self PrepareStream];
}
}
If someone can figure this out for me I'd be very grateful.

When you receive the notification, the parameter to your reachabilityChanged: method will be the notification itself. To get the Reachability object, you'll need to get it from the notification by sending -[NSNotification object] to the notification.
So something like this should work:
- (void) reachabilityChanged:(NSNotification *)note {
Reachability *reach = [note object];
if ([reach isReachable ]) {
NSLog(#"connection");
ServerFound = YES;
} else{
NSLog(#"no connection");
ServerFound = NO;
}
[self PrepareStream];
}

Related

Adding MBProgressHud to MPMoviePlayerController

I am trying to show MBProgressHud to MPMoviePlayerController, for that I am observing notifications for load states of MPMoviePlayer, but somehow Method observing notification never observes notifications for load states other then MPMovieLoadStatePlayable. I show MBProgressHud when video starts streaming but it does not work after it plays and then to pause to download video, Due to this I am unable to engage user while video is loading, If anyone has a better method please mention it or if there is any problem in the following code then let me know.
-(void)movieLoadStateDidChange:(NSNotification*)notification{
MPMoviePlayerController *player = [notification object];
if ((player.loadState & MPMovieLoadStatePlayable) == MPMovieLoadStatePlayable) {
NSLog(#"Load state Playable");
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}else if ((player.loadState & MPMovieLoadStatePlaythroughOK) == MPMovieLoadStatePlaythroughOK){
NSLog(#"Load state Playing");
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}else if ((player.loadState & MPMovieLoadStateStalled) == MPMovieLoadStateStalled){
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSLog(#"Load state stalled");
}else if ((player.loadState & MPMovieLoadStateUnknown) == MPMovieLoadStateUnknown){
NSLog(#"Load State unknown");
}
}
Ok .. i got your problem and the problem is that you are not getting notification for load states except MPMovieLoadStatePlayable. so here what you can do is...like below...
write down below notifiations in viewdidload
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerLoadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
After defining it in ViewDidLoad , implement those functions like below....
- (void) moviePlayerPlaybackDidFinish:(NSNotification *)notification
{
//your code....
MPMovieFinishReason finishReason = [notification.userInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
NSError *error = notification.userInfo[XCDMoviePlayerPlaybackDidFinishErrorUserInfoKey];
NSString *reason = #"Unknown";
switch (finishReason)
{
case MPMovieFinishReasonPlaybackEnded:
reason = #"Playback Ended";
break;
case MPMovieFinishReasonPlaybackError:
reason = #"Playback Error";
break;
case MPMovieFinishReasonUserExited:
reason = #"User Exited";
break;
}
NSLog(#"Finish Reason: %#%#", reason, error ? [#"\n" stringByAppendingString:[error description]] : #"");
}
- (void) moviePlayerPlaybackStateDidChange:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = notification.object;
NSString *playbackState = #"Unknown";
switch (moviePlayerController.playbackState)
{
case MPMoviePlaybackStateStopped:
playbackState = #"Stopped";
break;
case MPMoviePlaybackStatePlaying:
playbackState = #"Playing";
break;
case MPMoviePlaybackStatePaused:
playbackState = #"Paused";
break;
case MPMoviePlaybackStateInterrupted:
playbackState = #"Interrupted";
break;
case MPMoviePlaybackStateSeekingForward:
playbackState = #"Seeking Forward";
break;
case MPMoviePlaybackStateSeekingBackward:
playbackState = #"Seeking Backward";
break;
}
NSLog(#"Playback State: %#", playbackState);
}
- (void) moviePlayerLoadStateDidChange:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = notification.object;
NSMutableString *loadState = [NSMutableString new];
MPMovieLoadState state = moviePlayerController.loadState;
if (state & MPMovieLoadStatePlayable)
[loadState appendString:#" | Playable"];
if (state & MPMovieLoadStatePlaythroughOK)
[loadState appendString:#" | Playthrough OK"];
if (state & MPMovieLoadStateStalled)
[loadState appendString:#" | Stalled"];
NSLog(#"Load State: %#", loadState.length > 0 ? [loadState substringFromIndex:3] : #"N/A");
}
let me know it is working or not!!!
Happy Coding!!!!

Reachability method (startnotifier) is not calling

Here is my reference code. I have put break point in startnotifier method but it is not being called.
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
internetReach = [[Reachability reachabilityForInternetConnection] retain];
[internetReach startNotifier];
I have written this part of code in appdelegate.m (didFinishLaunchingWithOptions).
I have declared var in appdelegate.h like below....
#interface AppDelegate : UIResponder < UIApplicationDelegate >
{
Reachability *internetReach;
Reachability *wifiReach;
Reachability *hostReach;
}
Why breakpoint in startnotifier is not being called and hence nsnotification is not calling observer function if I change the network.
+(BOOL)ConnectedToNetWork
{
Reachability *HostReach = [Reachability reachabilityForInternetConnection];
NetworkStatus internetStatus = [HostReach currentReachabilityStatus];
bool result = false;
if (internetStatus == ReachableViaWiFi)
result = true;
else if(internetStatus==ReachableViaWWAN)
result = true;
return result;
}
use this method whre ever u want to check connection

Identify number of incoming call in iPhone

How do I know who is calling me?
Identify the number or even the contact in my list case I have.
I can identify if have or not a call, with this code.
void (^ctCallStateMuda)(NSNotification *) = ^(NSNotification * notification) {
NSString *callInfo = [[notification userInfo] objectForKey:#"callState"];
if ([callInfo isEqualToString:CTCallStateIncoming]) {
NSLog(#">>>>>> chegando");
} else if ([callInfo isEqualToString:CTCallStateConnected]) {
NSLog(#">>> atendendo <<<");
} else if ([callInfo isEqualToString:CTCallStateDisconnected]) {
NSLog(#"desconectado >>>>>>");
} else if ([callInfo isEqualToString:CTCallStateConnected]) {
NSLog(#"discando");
} else {
NSLog(#"nada");
}
};
CTCallCenter *callCenter;
callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler = ^(CTCall* aCallIncomming) {
NSDictionary *dict = [NSDictionary dictionaryWithObject:aCallIncomming.callState
forKey:#"callState"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"CTCallStateDidChange"
object:self
userInfo:dict];
};
[[NSNotificationCenter defaultCenter] addObserverForName:#"CTCallStateDidChange"
object:nil
queue:nil
usingBlock:ctCallStateMuda];
You don't have access to this information in the public SDK (a jailbroken iPhone is another matter). Apple prohibit apps from having access to any information relating to call history. The code you've posted above is so your app can detect when the user is receiving a phone call and adapt their interface accordingly, but that's it.

Get launch options without overriding didFinishLaunchingWithOptions:

I'm embedded in an environment (Adobe AIR) where I cannot override didFinishLaunchingWithOptions. Is there any other way to get those options? Are they stored in some global variable somewhere? Or does anyone know how to get those options in AIR?
I need this for Apple Push Notification Service (APNS).
Following the path in the link Michiel left ( http://www.tinytimgames.com/2011/09/01/unity-plugins-and-uiapplicationdidfinishlaunchingnotifcation/ ), you can create a class who's init method adds an observer to the UIApplicationDidFinishLaunchingNotification key. When the observer method is executed, the launchOptions will be contained in the notification's userInfo. I was doing this with local notifications so this was the implementation of my class:
static BOOL _launchedWithNotification = NO;
static UILocalNotification *_localNotification = nil;
#implementation NotificationChecker
+ (void)load
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(createNotificationChecker:)
name:#"UIApplicationDidFinishLaunchingNotification" object:nil];
}
+ (void)createNotificationChecker:(NSNotification *)notification
{
NSDictionary *launchOptions = [notification userInfo] ;
// This code will be called immediately after application:didFinishLaunchingWithOptions:.
UILocalNotification *localNotification = [launchOptions objectForKey: #"UIApplicationLaunchOptionsLocalNotificationKey"];
if (localNotification)
{
_launchedWithNotification = YES;
_localNotification = localNotification;
}
else
{
_launchedWithNotification = NO;
}
}
+(BOOL) applicationWasLaunchedWithNotification
{
return _launchedWithNotification;
}
+(UILocalNotification*) getLocalNotification
{
return _localNotification;
}
#end
Then when my extension context is initialized I check the NotificationChecker class to see if the application was launched with a notification.
BOOL appLaunchedWithNotification = [NotificationChecker applicationWasLaunchedWithNotification];
if(appLaunchedWithNotification)
{
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
UILocalNotification *notification = [NotificationChecker getLocalNotification];
NSString *type = [notification.userInfo objectForKey:#"type"];
FREDispatchStatusEventAsync(context, (uint8_t*)[#"notificationSelected" UTF8String], (uint8_t*)[type UTF8String]);
}
Hope that helps someone!

How often does the iPhone 4 search for data service once it has been lost?

Long time reader, first time asker.
I'm programming an iPhone application that needs to handle the phone going in and out of data coverage with some elegance. I can set up the Reachability with notifications to find out when it gets lost or comes back, but it would be helpful for me to know how often the radios are looking for a signal - and does this rate slow down over time? Also, is there anything I can do programmatically (like pinging a server when I know I don't have coverage) to speed it up?
Battery life is not really a big concern for me, and I will not be deploying through iTunes.
What you want is possible. First off get Reachability code from Apple. Then you need to write a checkNetworkStatus implementation. This is where notifications come -
#import "Reachability.h"
- (void)checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch(internetStatus)
{
case NotReachable:
{
self.internetActive = NO;
break;
}
case ReachableViaWiFi:
{
self.internetActive = YES;
break;
}
case ReachableViaWWAN:
{
self.internetActive = YES;
break;
}
}
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
self.hostActive = NO;
break;
}
case ReachableViaWiFi:
{
self.hostActive = YES;
break;
}
case ReachableViaWWAN:
{
self.hostActive = YES;
break;
}
}
return;
}
Now you need to start your notifications -
-(void)viewWillAppear:(BOOL)animated
{
//NSLog(#"View Will Appeared!!");
// check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(checkNetworkStatus:)
name:kReachabilityChangedNotification
object:nil];
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
// check if a pathway to a random host exists
hostReachable = [[Reachability reachabilityWithHostName: #"www.google.com"] retain];
[hostReachable startNotifier];
// now patiently wait for the notification
return;
}