2011-02-16 19 views
5

नहीं कहा जाता है मैं एक व्यू कंट्रोलर में एक वीडियो चला रहा हूं। जब उपयोगकर्ता हार्डवेयर होम बटन हिट करता है और वीडियो वर्तमान में सिम्युलेटर में EXC_BAD_ACCESS के साथ ऐप क्रैश चला रहा है।आईफोन: UIAplplicationWillResignActiveNotification कभी भी

मैंने पढ़ा कि मुझे वीडियो को रोकने से रोकने के लिए applicationWillResignActive संदेश का उपयोग करना चाहिए जो क्रैशिंग को हल करना चाहिए। तो मैं अधिसूचना केंद्र के साथ इस अधिसूचना के लिए पंजीकरण करने की कोशिश कर रहा हूं, लेकिन मेरे चयनकर्ता को कभी भी बुलाया नहीं जाता है। मैं क्या गलत कर रहा हूं?

निम्नलिखित कोड मेरे मीडिया प्लेयर दृश्य नियंत्रक में है:

- (void) playMedia {  
    NSURL *mediaUrl = [NSURL fileURLWithPath:tmpFilePath isDirectory:FALSE]; 
    player = [[MPMoviePlayerViewController alloc] initWithContentURL:mediaUrl]; 
    player.moviePlayer.controlStyle = MPMovieControlStyleEmbedded; 

    player.view.frame = self.view.frame;  
    [self.view addSubview:player.view]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(applicationWillResignActive:) 
               name:UIApplicationWillResignActiveNotification 
               object:nil]; 

    [player.moviePlayer play]; 
} 

- (void)applicationWillResignActive:(NSNotification *)notification { 
    // never gets called! 
    NSLog(@"resign active"); 
    [player.moviePlayer stop]; 
} 
+0

जबकि आप भविष्य में पाठकों के लिए 'ऑब्जेक्ट' के लिए 'ऑब्जेक्ट' के लिए सही ढंग से 'शून्य' पास कर रहे हैं, तो मैं ध्यान दूंगा कि यदि आप 'यूआईपीप्लिकेशन विलरिजिनएक्टिव नॉटिफिकेशन' के लिए 'शून्य' के अलावा कुछ और आपूर्ति करते हैं, तो 'चयनकर्ता' नहीं हो सकता है बुलाओ – Rob

उत्तर

1

सुनिश्चित नहीं हैं कि क्यों है कि एक नहीं है आप के लिए काम कर रहा है, लेकिन im एक ऑडियो प्लेयर में

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAction:) name:UIApplicationDidEnterBackgroundNotification object:nil];

सफलता के साथ

का उपयोग कर/रिकॉर्डर।

संभवतः एप्लिकेशन प्रतिनिधि में

- (void)applicationWillResignActive:(NSNotification *)notification { }

को लागू करने की कोशिश और अगर यह कहता है देखते हैं।

+0

क्या आप वाकई ऐप प्रतिनिधि में कम से कम इनके लिए पंजीकरण करने की ज़रूरत है? मैं इसके लिए पंजीकरण किए बिना आवेदनDidBecomeActive प्राप्त कर रहा हूँ। लेकिन जब आप होम बटन दबाते हैं तो मुझे कोई सूचना नहीं मिल रही है। – Oscar

+1

प्रतिनिधि उन्हें स्वचालित रूप से प्राप्त करता है। हर किसी को पंजीकरण करने की जरूरत है। –

7

ध्यान दें कि अगर आपके पास UIApplicationExitsOnSuspend कुंजी आपके ऐप की Info.plist में सत्य है, तो applicationWillResignActive विधि को कॉल नहीं किया जाता है जब उपयोगकर्ता होम बटन हिट करता है।

संबंधित मुद्दे