Rectangle 27 5

You should try to connect to the server with what you think is an appropriate timeout. NEVER use the reachability API until you've determined that your connection attempt failed and even then only if the error you receive from NSURLConnection et. al. is one that suggests you're not connected to the network. In that case, use the Reachability API to determine when you should try again.

Merely attempting a connection may bring up a network interface that wasn't available before.

This answer needs to be emphasized. Reachability has a lot of limitations to it and is not completely reliable. It can return true when there is no connection, in certain situations where network connection fluctuates. The only truly reliable way is to actually handle failure once your actual communication is attempted. Checking beforehand and assuming that it can't change in the meantime is a recipe for unhandled failure.

objective c - Check if iPhone is connected to the internet - Stack Ove...

iphone objective-c ios reachability
Rectangle 27 2

You can check for internet connection in swift using code below:

import SystemConfiguration

class Reachability: NSObject {

class func isConnectedToNetwork() -> Bool {
    var zeroAddress = sockaddr_in()
    zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
    zeroAddress.sin_family = sa_family_t(AF_INET)
    let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
        SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
    }
    var flags = SCNetworkReachabilityFlags()
    if !SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) {
        return false
    }
    let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0
    let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
    return (isReachable && !needsConnection)
}

objective c - Check if iPhone is connected to the internet - Stack Ove...

iphone objective-c ios reachability
Rectangle 27 13

In 3.1 there are two protocols that support outputting audio to bluetooth devices and the use depends on the accessory. The first is A2DP which is used with accessores that support recieving stereo music, and the other is hands free for all handfree accesories. To activate the first option, you need to use the MPVolumeView class which has a volume slider and a audio device selection button, when this view is added to any of the views in the app, it provides a way for the user to set the volume and select a BT device if connected ( this is the only way I found) On the other hand, the second option can be activated using the call

UInt32 bt = TRUE;
 result = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryEnableBluetoothInput , sizeof(UInt32), &bt);

The appliction must initialize the audio session and use the corect catagory ( it must support recoding for this to work). After the EnableBluetoothInput is set all Input and output audio will be routed through the handsfree device ( if connected of course :) )

objective c - Select Audio device on iPhone - Stack Overflow

iphone objective-c audio bluetooth
Rectangle 27 28

Apple Developer Connection has a sample application (Reachability) that uses the System Configuration framework to determine network status. It will tell you whether you have a WiFi, EDGE/3G or no Internet connection.

You would use portions of this code in your application to determine network state, and then provide interface cues if no connection is available, such as a UIAlertView.

There's a nice reworking of the Apple Reachability sample here: blog.ddg.com/?p=24 It's designed to be a like-for-like drop-in. He's taken some care with it (way more than Apple) and I've successfully used his Reachability implementation without any issues. Note that if you use the ASIHTTP library, the abovementioned Reachability rewrite comes as part of that.

i am using reachability but it gives problem. because it shows alert more then one time and it really irritates

objective c - iPhone SDK Internet connection detection - Stack Overflo...

iphone objective-c
Rectangle 27 28

Apple Developer Connection has a sample application (Reachability) that uses the System Configuration framework to determine network status. It will tell you whether you have a WiFi, EDGE/3G or no Internet connection.

You would use portions of this code in your application to determine network state, and then provide interface cues if no connection is available, such as a UIAlertView.

There's a nice reworking of the Apple Reachability sample here: blog.ddg.com/?p=24 It's designed to be a like-for-like drop-in. He's taken some care with it (way more than Apple) and I've successfully used his Reachability implementation without any issues. Note that if you use the ASIHTTP library, the abovementioned Reachability rewrite comes as part of that.

i am using reachability but it gives problem. because it shows alert more then one time and it really irritates

objective c - iPhone SDK Internet connection detection - Stack Overflo...

iphone objective-c
Rectangle 27 2

I have connected my iPhone with iOS 8 installed to Xcode 5.1.First time it doesn't recognize.but when i unplugged device and connect again , Device Recognized. I dont know the reason Anyway i am sure that you can also connect your IOS8 installed device to Xcode5.1 ....

objective c - Xcode 5 not detecting iPhone running iOS 8 - Stack Overf...

objective-c xcode5 ios8
Rectangle 27 1

The answer I posted on Sept 18 is incorrect, it only detects if it is connected to network, not internet. Here is the correct solution using AlamoFire:

import Alamofire

class ReachabilityObserver {

    fileprivate let reachabilityManager = NetworkReachabilityManager()
    fileprivate var reachabilityStatus: NetworkReachabilityManager.NetworkReachabilityStatus = .unknown

    var isOnline: Bool {
        if (reachabilityStatus == .unknown || reachabilityStatus == .notReachable){
            return false
        }else{
            return true
        }
    }

    static let sharedInstance = ReachabilityObserver()
    fileprivate init () {
        reachabilityManager?.listener = {
            [weak self] status in

            self?.reachabilityStatus = status
            NotificationCenter.default.post(
                name: NSNotification.Name(rawValue: ClickUpConstants.ReachabilityStateChanged),
                object: nil)
        }
        reachabilityManager?.startListening()
    }
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
     _ = ReachabilityObserver.sharedInstance
     return true
}

3) Use this anywhere in your app to detect if online, such as in view did load, or when action occurs

if (ReachabilityObserver.sharedInstance.isOnline){
    //User is online
}else{
    //User is not online
}

objective c - How to check internet connection on iOS device? - Stack ...

ios objective-c cocoa-touch reachability
Rectangle 27 1

'Reachability' doesn't work since it won't detect if there is a response from the host or not. It will just check if the client can send out a packet to the host. So even if you are connected to a WiFi network and the WiFi's internet is down or the server is down, you will get a "YES" for reachability.

A better method is to try an HTTP request and verify the response.

NSURL *pageToLoadUrl = [[NSURL alloc] initWithString:@"https://www.google.com/"];
NSMutableURLRequest *pageRequest = [NSMutableURLRequest requestWithURL:pageToLoadUrl];
[pageRequest setTimeoutInterval:2.0];
AFHTTPRequestOperation *pageOperation = [[AFHTTPRequestOperation alloc] initWithRequest:pageRequest];
AFRememberingSecurityPolicy *policy = [AFRememberingSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setDelegate:self];
currentPageOperation.securityPolicy = policy;
if (self.ignoreSSLCertificate) {
    NSLog(@"Warning - ignoring invalid certificates");
    currentPageOperation.securityPolicy.allowInvalidCertificates = YES;
}
[pageOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    internetActive = YES;
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
    NSLog(@"Error:------>%@", [error description]);
    internetActive = NO;
}];
[pageOperation start];

Only catch is that the "internetActive" gets updated with a delay upto the timeout mentioned in the above code. You can code inside the callback to act on the status.

objective c - How to check internet connection on iOS device? - Stack ...

ios objective-c cocoa-touch reachability
Rectangle 27 1

Another example would be if you're improperly connected to a Wifi network - your phone has a good connection but no permission to access any pages on the Internet.

In this case, the only method of detection would be to try and send a web request to a reliable site (say www.google.com). If your request to this source times out after a set amount of time (say five seconds) then you can safely conclude that the phone has connectivity issues.

objective c - How to check whether internet is active (checking both n...

ios objective-c reachability connectivity
Rectangle 27 1

Sounds like you might have the button connected to both actions, check in Interface Builder. Right-click the button, and expand the connections under 'Actions'.

If this is the case, you'll see the immediateActivate: fire first, then delatedActivate: fire 5 seconds later. You can check this using a couple of breakpoints or NSLog(@"Here!"); statements.

BTW - I prefer this style NSLog(@"%s", __FUNCTION__); so the console shows which method you are in. I sprinkle this throughout my application along with some notable parameter(s).

@mobibob I do the same, but I add a bunch of #ifdef DEBUG/#endif around the logs, so I don't have to refactor when building for production.

objective c - why does performSelector: afterDelay: act immediately in...

iphone objective-c
Rectangle 27 1

To clarify what I am saying if you connect a "UINavigationController" in Interface Builder you do not need to alloc/init. But if you are hand coding it you need to alloc/init it before you [window addSubview:]

I suppose what you mean is the code <pre> [[optionsViewController alloc] initWithNibName:@"optionsViewController" bundle:nil];</pre> ? Yes I alloc / init and even give it the nib name.

Still not showing then?

No it is still not showing up. I have set breakpoints in the optionsViewController and it does not get even to the DidLoad method. As you said I guess there is still a missing link somewhere....

objective c - iPhone navigationController is not displayed - Stack Ove...

iphone objective-c uinavigationcontroller pushviewcontroller
Rectangle 27 1

- (void) connectedToNetwork 
{
    BOOL aflag = ([NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.co.in/"] encoding:NSASCIIStringEncoding error:nil]!=NULL)?YES:NO; 
    if (!aflag) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Sorry!....You are not connected to network " 
                              delegate:self cancelButtonTitle:@"Exit" otherButtonTitles:nil];
        [alert show];
        [alert release];

    }
}

iphone - What is the "stringWithContentsOfURL" replacement for objecti...

iphone objective-c
Rectangle 27 3

// Check whether the user has internet
- (bool)hasInternet {
    NSURL *url = [[NSURL alloc] initWithString:@"http://www.google.com"];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0];
    BOOL connectedToInternet = NO;
    if ([NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]) {
        connectedToInternet = YES;
    }
    //if (connectedToInternet)
        //NSLog(@"We Have Internet!");
    [request release];
    [url release];
    return connectedToInternet;
}

This is a bad solution. Your application will freeze until the request succeeds or fails. This could cause your application to stall for up to 60 seconds if they have a routing problem that causes the request not to fail until the timeout is reached. Your user will not appreciate this. Even if it succeeds, the application will likely stall for several seconds, especially over a slow connection.

But what if you use NSOperation, or GCD wor this method ? I think it will work fine, and won't freeze UI.

It is not a good practice to test connection reachability on a fixed URL like this. What can you say if Google is offline but client has internet? Additionally, this test fails in many cases where you test connection on a HTTPS url. Thumbs down for this answer.

objective c - How to determine Internet Connection in Cocoa? - Stack O...

objective-c osx cocoa
Rectangle 27 3

// Check whether the user has internet
- (bool)hasInternet {
    NSURL *url = [[NSURL alloc] initWithString:@"http://www.google.com"];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0];
    BOOL connectedToInternet = NO;
    if ([NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]) {
        connectedToInternet = YES;
    }
    //if (connectedToInternet)
        //NSLog(@"We Have Internet!");
    [request release];
    [url release];
    return connectedToInternet;
}

This is a bad solution. Your application will freeze until the request succeeds or fails. This could cause your application to stall for up to 60 seconds if they have a routing problem that causes the request not to fail until the timeout is reached. Your user will not appreciate this. Even if it succeeds, the application will likely stall for several seconds, especially over a slow connection.

But what if you use NSOperation, or GCD wor this method ? I think it will work fine, and won't freeze UI.

It is not a good practice to test connection reachability on a fixed URL like this. What can you say if Google is offline but client has internet? Additionally, this test fails in many cases where you test connection on a HTTPS url. Thumbs down for this answer.

objective c - How to determine Internet Connection in Cocoa? - Stack O...

objective-c osx cocoa
Rectangle 27 1

Building on top of what Raxit mentions, I use the following code (extracted from the reachability example mentioned by Raxit) to check for internet access in my application delegate:

- (BOOL)isReachableWithoutRequiringConnection:(SCNetworkReachabilityFlags)flags
{
    BOOL isReachable = flags & kSCNetworkReachabilityFlagsReachable;

    BOOL noConnectionRequired = !(flags & kSCNetworkReachabilityFlagsConnectionRequired);
    if ((flags & kSCNetworkReachabilityFlagsIsWWAN)) {
        noConnectionRequired = YES;
    }

    return (isReachable && noConnectionRequired) ? YES : NO;
}

- (BOOL)isHostReachable:(NSString *)host
{
    if (!host || ![host length]) {
        return NO;
    }

    SCNetworkReachabilityFlags        flags;
    SCNetworkReachabilityRef reachability =  SCNetworkReachabilityCreateWithName(NULL, [host UTF8String]);
    BOOL gotFlags = SCNetworkReachabilityGetFlags(reachability, &flags);

    CFRelease(reachability);

    if (!gotFlags) {
        return NO;
    }

    return [self isReachableWithoutRequiringConnection:flags];
}


- (BOOL)connectedToNetwork {

    return [self isHostReachable:@"www.hostyoureallycareabouthavingaconnectionwith.com"];
}

objective c - How to check Internet status in iPhone - Stack Overflow

iphone objective-c xcode
Rectangle 27 5

Had the same problem. It's the way you terminate the debugging process. Just add another step:

4) STOP the application (from XCode)

ok this fixed it thanks, so then I have two different crashes that are not linked, because the app still crashes after beeing submited to the app store :(

@xtrimsky: ouch, that other crash is from your code or the way you're compiling it. Check Will's answer to see if you can read crash logs. Also: it might be possible that your app is crashing only on very certain type of devices/iOS-es. Check this link: stackoverflow.com/questions/9567359/

@xtrimsky: in that linked answer check if this applies to your app: are you creating any UIImageViews, UIImages or something similiar in the background thread?

here is my crashlog, I don't see anything helpful but I'm trying to understand it: pastebin.com/4Lhhdiyj

objective c - iPhone app under dev crashes if phone not connected thro...

iphone objective-c ios xcode
Rectangle 27 4

You can look at the logs that were recorded when the app crashed by plugging it back into your Mac, opening Xcode, going to the Organizer (CMD+SHIFT+2) and looking at the Console for your device. Hopefully here you should be able to see what's causing the crash.

objective c - iPhone app under dev crashes if phone not connected thro...

iphone objective-c ios xcode
Rectangle 27 1

Private declarations are not exposed to Objective-C unless they are explicitly marked with @IBAction, @IBOutlet, or @objc as well.

So, if you have an "open" keyword before class definition, it should be ok.

public class

When I want to use it in an objective-C class, the classes of the Swift project are not available. Maybe I should create an intermediary Swift class.

Well, in SyntaxKit/SyntaxKit.podspec there are no option specified for spec.module_name. Try to add in this file following line: spec.module_name = "SyntaxKit". clean and rebuild project as well

It does not work from an ObjC class. It seems I can only access the classes that subclass NSObject.

Is it possible to use a pod written in Swift in an Objective-C project...

objective-c swift cocoapods
Rectangle 27 0

#import "Reachability.h"
-(BOOL)CheckNetwork   {
ATReachability *Reachability = [ATReachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus NetworkStatus = [Reachability currentReachabilityStatus];
return NetworkStatus; }
if([self CheckNetwork] == NotReachable) { /* No Network */ } else { /* Network */ }
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    if([self CheckNetwork] == NotReachable) {
        /* No Network */ 
    } else { 
        /* Network */
    }
}
-(IBAction)NetworkCheck {
    //Use this to "call" the check
    UIWebView *networkChecker = [[UIWebView alloc] init];
    [networkChecker loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]]];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    NSString *checkError = [[error debugDescription] substringFromIndex:[[error debugDescription] length] -35];

    if ([checkError isEqualToString:@"\"Could not connect to the server.\"}"]) { /* No Network */ }
    if ([checkError isEqualToString:@"Could not connect to the server.\"}"]) { /* No Network */ }
    if ([checkError isEqualToString:@"\"connection appears to be offline.\"}"]) { /* No Network */ }
    if ([checkError isEqualToString:@"connection appears to be offline.\"}"]) { /* No Network */ }
}

Tip: Works great with SVProgressHUD ;)

objective c - How to check for an active Internet Connection on iPhone...

iphone objective-c ios cocoa-touch reachability
Rectangle 27 0

I've used the code in this discussion, and it seems to work fine (read the whole thread!).

I haven't tested it exhaustively with every conceivable kind of connection (like ad hoc wifi).

objective c - How to check for an active Internet Connection on iPhone...

iphone objective-c ios cocoa-touch reachability