We need when wifi connected in iPhone mobile.We need open app-story in browser automatically.i.e We have 4 wifi's Himansu,hits,poll,hotspot.We need When wifi connect Humans after connected it's redirect to below link
https://itunes.apple.com/in/app/facebook/id284882215?mt=8
Please give me any idea.First tell me it's possible or not
Using the code apple provide here
Reachability *reach = [Reachability reachabilityForInternetConnection];
[reach startNotifier];
NetworkStatus status = [reach currentReachabilityStatus];
if(status == NotReachable)
{
//No internet
}
else if (status == ReachableViaWiFi)
{
//WiFi
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/in/app/facebook/id284882215?mt=8"]];
}
else if (status == ReachableViaWWAN)
{
//3G
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/in/app/facebook/id284882215?mt=8"]];
}
getting Wifi network Name
Step 1:
import the framework #import <SystemConfiguration/CaptiveNetwork.h>
Step -2
implement the method in
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
NSLog(#"Connected at:%#",myDict);
NSDictionary *myDictionary = (__bridge_transfer NSDictionary*)myDict;
NSString * SSID = [myDictionary objectForKey:#"SSID"];
NSLog(#"bssid is %#", SSID);
// your console output is just like
SSID = "Eqra'aOrange";
Step - 3
now you check your condition
if ([SSID isEqualToString:#"Himansu"])
{
// customize your code
}
else
{
// do your stuff
}
Related
In some applications, like WhatsApp, when I send a message with no internet connection then close(terminate) the app, the message will be sent when internet comes back.
I'm trying to do the same thing and I wonder if there is any way to check for an internet connection when my app is not running and in the foreground in order to do a specific task.
Reachability
Example:
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];
if (remoteHostStatus == NotReachable) {
// not reachable
} else if (remoteHostStatus == ReachableViaWiFi) {
// reachable via Wifi
} else if (remoteHostStatus == ReachableViaWWAN) {
// reachable via WWAN
}
Edit
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Initialize Reachability
Reachability *reachability = [Reachability reachabilityWithHostname:#"www.google.com"];
// Start Monitoring
[reachability startNotifier];
//your code
return YES;
}
Every time the network interface changes, reachabilityDidChange: is invoked
- (void)reachabilityDidChange:(NSNotification *)notification{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];
if (remoteHostStatus == NotReachable) {
// not reachable
} else if (remoteHostStatus == ReachableViaWiFi) {
// reachable via Wifi
} else if (remoteHostStatus == ReachableViaWWAN) {
// reachable via WWAN
}
}
This will solve your problem.
I got a Notification Center Widget that contains some UISwitches that work only if connected to a Wi-Fi network.
I tried to do this with Reachability (that works in the normal app code), like this
#import "Reachability.h"
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
if(status == NotReachable) {
switch.enabled = NO;
} else if (status == ReachableViaWiFi) {
} else if (status == ReachableViaWWAN) {
switch.enabled = NO;
}
But I got these errors
Probably your not add Reachability.m as Target Membership of your widget
In iPhone 5S WiFi detected as 3G and in my iPhone 4 it's normal.
Both in iOS 7.1.
In some devices it happens as well.
WiFi disabled and 3G connected, I double checked to see if internet connection is ok and indeed it's ok in device itself.
Any idea why?
Edit 1:
Code below:
- (void)registerReachabilityNotification
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(checkNetworkStatus:)
name:kReachabilityChangedNotification object:nil];
Reachability *reach = [Reachability reachabilityForInternetConnection];
[reach startNotifier];
NSNotification *note = [[NSNotification alloc] initWithName:kReachabilityChangedNotification object:reach userInfo:nil];
[self checkNetworkStatus:note];
}
- (void)checkNetworkStatus:(NSNotification*)notification
{
Reachability *reach = notification.object;
NSParameterAssert([reach isKindOfClass: [Reachability class]]);
NetworkStatus internetStatus = [reach currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(#"No internet connection.");
break;
}
case ReachableViaWiFi:
{
NSLog(#"The internet is working via WIFI.");
break;
}
case ReachableViaWWAN:
{
NSLog(#"The internet is working via WWAN.");
break;
}
}
}
Edit 1:
This code:
NetworkStatus nStats = [[Reachability reachabilityForLocalWiFi] currentReachabilityStatus];
if (nStats != ReachableViaWiFi) {
NSLog(#"nStats != ReachableViaWiFi");
}
if (nStats == ReachableViaWiFi) {
NSLog(#"WIFI");
}
else if (nStats == ReachableViaWWAN) {
NSLog(#"WWAN");
}
else if (nStats == NotReachable) {
NSLog(#"not reachable");
}
else {
NSLog(#"undetermined reachability.");
}
Give me this:
Reachability Flag Status: WR t------ localWiFiStatusForFlags
nStats != ReachableViaWiFi
not reachable
My method was completely wrong, below code for correct way:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(#"CONNECTION: %#", NSStringFromNetworkStatus([MobileControlHandler checkConnection]));
return YES;
}
+ (NetworkStatus)checkConnection
{
NetworkStatus wifiStatus = [[Reachability reachabilityForLocalWiFi] currentReachabilityStatus];
NetworkStatus internetStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
if (wifiStatus == ReachableViaWiFi) {
return ReachableViaWiFi;
}
else if (wifiStatus != ReachableViaWiFi && internetStatus == ReachableViaWWAN) {
return ReachableViaWWAN;
}
else {
return NotReachable;
}
}
FOUNDATION_EXPORT NSString *NSStringFromNetworkStatus(NetworkStatus netStatus)
{
if (netStatus == ReachableViaWiFi) {
return #"ReachableViaWiFi";
} else if (netStatus == ReachableViaWWAN) {
return #"ReachableViaWWAN";
} else if (netStatus == NotReachable) {
return #"NotReachable";
} else {
return #"Undetermined reachbility flag";
}
}
Plot:
Reachability Flag Status: WR t------ localWiFiStatusForFlags
Reachability Flag Status: WR t----l- networkStatusForFlags
CONNECTION: ReachableViaWWAN
Just download new Reachability class from Apple
https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html
it will work on ios 8 too.
For more interacting things about iOS app development, Checkout
https://appengineer.in/
#import <Reachability.h>
It's a singleton so you can start using it right away.
Ex:
if ([Reachability currentReachabilityStatus] == NotReachable) {
...
}
I start monitoring like this in my AppDelegate:
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
On my root controller I then need to check if reachability is available and I perform this action to decide how to draw my UI:
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
NSLog(#"%s - %#", __FUNCTION__, AFStringFromNetworkReachabilityStatus([manager networkReachabilityStatus]));
switch ([manager networkReachabilityStatus]){
case AFNetworkReachabilityStatusNotReachable:
[self showNetworkUnreachable];
break;
default:
[self hideNetworkUnreachable];
}
My issue is that here status is always unknown even if the device has connection.
Possibly AfNetworking is not the right tool to be used here. Any suggestion?
Not working in my case too. I used that instead:
- (BOOL)isInternetConnectionAvailable
{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus internetStatus = [reachability currentReachabilityStatus];
if (internetStatus != NotReachable) {
return YES;
}
else
{
NSLog(#"NO INTERNET CONNECTION");
return NO;
}
}
How can I check whether the app is connected to the internet or not?
currently, I am using this code in my appdelegate.m file
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);
}
});
and when I click my login button I want to do a check whether the internet is connected or not using NSnotificationcenter?
Please help me
After download bellow example.
http://developer.apple.com/iphone/library/samplecode/Reachability/index.html
you can use it in your Project like bellow steps:-
included Apple's Reachability.h & .m from their Reachability example.
add the SystemConfiguration framework.
put bellow method in to your appdelegare.m file:-
- (BOOL) connectedToNetwork{
Reachability* reachability = [Reachability reachabilityWithHostName:#"google.com"];
NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];
if(remoteHostStatus == NotReachable)
{
isInternet =NO;
}
else if (remoteHostStatus == ReachableViaWWAN)
{
isInternet = TRUE;
}
else if (remoteHostStatus == ReachableViaWiFi)
{ isInternet = TRUE;
}
return isInternet;
}
isInternet is a BOOL declear in to your .h class
as per your code:-
dispatch_queue_t connectivityThread = dispatch_queue_create("com.GMM.assamkart.connectivity", NULL);
dispatch_async(connectivityThread, ^{
while (true){
isInternet =[self connectedToNetwork];
if (isInternet)
{
NSLog(#"connected");
}
else
{
NSLog(#"Not connected");
}
// usleep(10000000);
}
});
-(BOOL) connectedToInternet
{
NSString *URLString = [NSString stringWithContentsOfURL:[NSURL URLWithString:#"http://www.google.com"]];
return ( URLString != NULL ) ? YES : NO;
}