For this you have check internet, for this make a internet validation class and then call that class every place where you are using internet.
In your .h file make a static method, like given below.
#import <Foundation/Foundation.h>
@interface InternetValidation : NSObject {
}
+ (BOOL) connectedToNetwork;
@end
Then, in your .m file
#import "InternetValidation.h"
#import <SystemConfiguration/SCNetworkReachability.h>
#include <netinet/in.h>
@implementation InternetValidation
+ (BOOL) connectedToNetwork
{
BOOL success = NO;
const char *host_name = [@"google.com"
cStringUsingEncoding:NSASCIIStringEncoding];
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL,
host_name);
SCNetworkReachabilityFlags flags;
success = SCNetworkReachabilityGetFlags(reachability, &flags);
BOOL isAvailable = success && (flags & kSCNetworkFlagsReachable) && !(flags & kSCNetworkFlagsConnectionRequired);
if (isAvailable) {
success = YES;
}else{
success = NO;
}
//NSLog(@"%d",success);
return success;
}
@end
Now, Import this class where you want to check internet.
Then Call that internet Class Method like this way.
if ([InternetValidation connectedToNetwork]){
//Do your code here.
}
else{
// No Internet;
}