में गम्यता का पता लगाने मैं संभावना लागू करने के लिए अलग तरह से परीक्षण किया गया है जब एप्लिकेशन पृष्ठभूमि में है कि उपकरण वापस इंटरनेट प्राप्त यदि ऐसा है तो पहले कोड मैं परीक्षण एप्पल गम्यता नमूना कोड http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.htmlपृष्ठभूमि
था पता करने के लिए लेकिन जब यह पृष्ठभूमि पृष्ठभूमि में ऐप है तो यह कोड इंटरनेट स्थिति को सूचित नहीं करता है। इसलिए मैं भी folowing कोड की कोशिश की और जब अनुप्रयोग अग्रभूमि (एप्पल गम्यता नमूना कोड के रूप में ही)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(checkNetworkStatus:)
name:kReachabilityChangedNotification object:nil];
// Set up Reachability
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
...
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(checkNetworkStatus:)
name:kReachabilityChangedNotification object:nil];
// Set up Reachability
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
}
- (void)checkNetworkStatus:(NSNotification *)notice {
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"The internet is down.");
break;
}
case ReachableViaWiFi:
{
NSLog(@"The internet is working via WIFI");
//Alert sound in Background when App have internet again
UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
if (notification) {
[notification setFireDate:[NSDate date]];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[notification setRepeatInterval:0];
[notification setSoundName:@"alarmsound.caf"];
[notification setAlertBody:@"Send notification internet back"];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
break;
}
case ReachableViaWWAN:
{
NSLog(@"The internet is working via WWAN!");
//Alert sound in Background when App have internet again
UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
if (notification) {
[notification setFireDate:[NSDate date]];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[notification setRepeatInterval:0];
[notification setSoundName:@"alarmsound.caf"];
[notification setAlertBody:@"Send notification internet back"];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
break;
}
}
}
मेरा प्रश्न है करने के लिए पृष्ठभूमि राज्य से शुरू की है यह काम:क्या रास्ता ही सूचना प्राप्त करना, जब इंटरनेट जब ऐप पृष्ठभूमि में होता है तो राज्य बदल जाता है?
हाय, सबसे पहले आपको ध्यान रखना चाहिए कि ऐप्पल बहुत सख्त है कि किस प्रकार के ऐप्स पृष्ठभूमि निष्पादन करने में सक्षम होंगे। एप्पल द्वारा इस दस्तावेज़ पर Pls पर एक नज़र डालें। https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html। इसके अलावा, कृपया यह बताने की कोशिश करें कि आपका ऐप क्या करने का प्रयास कर रहा है। शायद हम एक बेहतर दृष्टिकोण की पेशकश कर सकते हैं! –