मेरे पास कई आईओएस ऐप्स हैं जो सभी एक ही पोर्ट का उपयोग नेटवर्क बीकन सुनने के लिए करते हैं। मुख्य दृश्य पर जब मैं एक और दृश्य खोला जाता है, तो पोर्ट बंद करने के लिए ViewWillDisappear का उपयोग करता है, जो बहुत अच्छा काम कर रहा था। तब मैंने देखा कि अगर मैंने बंदरगाह को बंद करने के लिए एक और दृश्य खोलने के बिना मुख्य दृश्य नियंत्रक से होम बटन दबाया, तो बंदरगाह खुला रहता है और मेरे अन्य ऐप्स में से कोई भी उस बंदरगाह पर और नहीं सुन सकता है। मैंने फिर viewWillUnload का उपयोग करने का प्रयास किया, लेकिन जब मैं होम बटन दबाता हूं तो ऐसा नहीं लगता है।पता लगाएं कि घर बटन दबाए जाने पर पता लगाएं आईओएस
-(void)viewWillUnload
{
//[super viewWillUnload];
NSLog(@"View will unload");
[udpSocket close];
udpSocket = nil;
}
देखें अनलोड को कंसोल में कभी प्रदर्शित नहीं किया जाएगा, जो मुझे विश्वास दिलाता है कि विधि कभी नहीं कह रही है।
क्या घर बटन दबाए जाने का पता लगाने का कोई तरीका है ताकि मैं अपना बंदरगाह बंद कर सकूं?
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
कोशिश
अवहेलना
onStop()
औरonStart()
अंदर बच्चे "applicationWillTerminate" विधि ।:-) –"applicationWillTerminate" विधि मौजूद नहीं है। हालांकि, उप-वर्ग UIAplplicationWillTerminateNotification के लिए पंजीकरण कर सकते हैं और फिर अपना स्वयं का सफाई या बंद कर सकते हैं। –