1. In
#import "AppDelegate.h"
{
reachability *hostreach;
}
2. In
-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {}
//monitoring network situation
[[nsnotificationcenter defaultcenter] addobserver: Self
selector:@selector(reachabilitychanged:)
name: kreachabilitychangednotification
Object: nil];
//Initialize the Reachability class and add a monitored URL.
Hostreach = [reachability reachabilitywithhostname:@ "https://www.baidu.com"];
//Start monitoring
[hostreach startnotifier];
3.
#pragma mark-monitors network conditions and calls when the network changes
-(void) reachabilitychanged: (nsnotification *) Note {
reachability* Curreach = [Note object];
Nsparameterassert([Curreach iskindofclass: [reachability class]]);
networkstatus status = [Curreach currentreachabilitystatus];
if (status = = notreachable) {
//Initialize the prompt box;
uialertcontroller *alert = [uialertcontroller alertcontrollerwithtitle:@ "Prompt" Message:@ "Clean cache" preferredstyle: uialertcontrollerstylealert];
[Alert addaction: [uialertaction actionwithtitle:@ ' OK ' style: Uialertactionstyledefault Handler: ^ (uialertaction * _nonnull action) {
//Click the button response event;
}]];
//popup notification box;
[self. Window. Rootviewcontroller presentviewcontroller: Alert animated:true completion :nil];
}
}
Real-time monitoring of app networks for iOS development