IOS Off-screen processing

Source: Internet
Author: User

IOS Off-screen processing(2014-01-13 18:13:21) reproduced
Tags: it

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

{

Self.window = [[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]] autorelease];

Turn on network condition monitoring

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (reachabilitychanged:) Name: Kreachabilitychangednotification Object:nil];

Self.hostreach = [reachability reachabilitywithhostname:@ "www.baidu.com"];

[Self.hostreach Startnotifier]; Start listening, a run loop is started

Self.window.rootViewController = Self.tabbarcontroller;

[Self.window makekeyandvisible];

return YES;

}

The method that will be called when the network link changes

-(void) reachabilitychanged: (nsnotification *) Note

{

reachability *currreach = [Note Object];

Nsparameterassert ([Currreach iskindofclass:[reachability class]]);

Respond to changes in connection to process actions

NetworkStatus status = [Currreach currentreachabilitystatus];

Pop-up reminder if not connected to the network

self.isreachable = YES;

if (status = = Notreachable)

{

Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Network connection exception" message:@ "temporarily unable to access bookstore information" Delegate:nil Cancelbuttontitle: @ "OK" otherbuttontitles:nil];

[Alert show];

[Alert release];

self.isreachable = NO;

}

Else

{

Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Network connection Information" message:@ "Network connection OK" Delegate:nil cancelbuttontitle:@ " Determine "Otherbuttontitles:nil";

[Alert show];

[Alert release];

self.isreachable = YES;

}

}

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

{

Self.window = [[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]] autorelease];

Turn on network condition monitoring

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (reachabilitychanged:) Name: Kreachabilitychangednotification Object:nil];

Self.hostreach = [reachability reachabilitywithhostname:@ "www.baidu.com"];

[Self.hostreach Startnotifier]; Start listening, a run loop is started

Self.window.rootViewController = Self.tabbarcontroller;

[Self.window makekeyandvisible];

return YES;

}

The method that will be called when the network link changes

-(void) reachabilitychanged: (nsnotification *) Note

{

reachability *currreach = [Note Object];

Nsparameterassert ([Currreach iskindofclass:[reachability class]]);

Respond to changes in connection to process actions

NetworkStatus status = [Currreach currentreachabilitystatus];

Pop-up reminder if not connected to the network

self.isreachable = YES;

if (status = = Notreachable)

{

Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Network connection exception" message:@ "temporarily unable to access bookstore information" Delegate:nil Cancelbuttontitle: @ "OK" otherbuttontitles:nil];

[Alert show];

[Alert release];

self.isreachable = NO;

}

Else

{

Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Network connection Information" message:@ "Network connection OK" Delegate:nil cancelbuttontitle:@ " Determine "Otherbuttontitles:nil";

[Alert show];

[Alert release];

self.isreachable = YES;

}

}

Using the code above, you can use the following singleton to determine whether the network is connected in any one of the application's interfaces

[CPP] View plaincopyprint?

Appdelegate *appdlg = (appdelegate *) [[uiapplication sharedapplication] delegate];

if (appdlg.isreachable)

{

NSLog (@ "Network is connected");//code to perform network uptime

}

Else

{

NSLog (@ "Network connection exception");//code to execute network exception

}

IOS Off-screen processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.