2012-10-25 12 views
11

आईओएस 6 और आईपैड के लिए लक्षित एक्सकोड 4.5 में कोकोस 2 डी 2.1 टेम्पलेट (कोई भौतिकी इंजन नहीं) शुरू किया। CDAudioManager.m फ़ाइल, निम्न कोड ...कोकोस 2 डी 2.1: "प्रतिनिधि" आईओएस 6 में बहिष्कृत किया गया। मैं इस AVAudioSession के लिए प्रतिनिधि कैसे सेट करूं?

AVAudioSession* session = [AVAudioSession sharedInstance]; 
session.delegate = self; // Which is what is automatically generated by the template. 

में ... निम्न चेतावनी उत्पन्न करता है ...

"delegate deprecated: first deprecated in iOS 6" 

तो मैं सेब डेवलपर दस्तावेज़ पर जाएँ, और उसके तहत आने वाले कहते हैं "प्रतिनिधि," "आईओएस 6.0 में बहिष्कृत। इसके बजाय इस वर्ग के अधिसूचना अनुभाग में वर्णित अधिसूचनाओं का प्रयोग करें।"

http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioSession_ClassReference/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/AVAudioSession/delegate

समस्या है, यह सब हम क्या करने की कोशिश कर रहे की तरह मुझे लग रहा है - मेरी अनुभवहीनता माफ - CDAudioManager उदाहरण ही AVAudioSession के लिए प्रतिनिधि निर्धारित है। अधिसूचनाएं इसे कैसे पूरा करती हैं? या मैं उपर्युक्त कोड के लक्ष्य के बारे में गलत हूं?

उत्तर

17

त्रुटि आप में चल रहे हैं कोड

AVAudioSession* session = [AVAudioSession sharedInstance]; 
session.delegate = self;// <-------- DEPRECATED IN IOS 6.0 

के इस खंड में है मौन करने के लिए चेतावनी इस के लिए उन 2 पंक्तियों में परिवर्तन:

[[AVAudioSession sharedInstance] setActive:YES error:nil]; 

आशा इस मदद करता है।

+10

"क्यों" यह सही है? – Jonny

+0

ऐप्पल ने आईओएस 6 में प्रतिनिधि और AVAudioSessionDelegate प्रोटोकॉल को सेट करने से वंचित कर दिया और अब आपको NSNotification केंद्र के माध्यम से अधिसूचनाओं को सुनना होगा। – geekinit

+9

यह उत्तर अपूर्ण दिखता है। –

9

मुझे कोकोस 2 डी-iPhone.org फ़ोरम पर इसके बारे में एक विवाद मिला। जबकि मैं इसे पूरी तरह से समझ नहीं पा रहा हूं - लेकिन मैं इस पर काम कर रहा हूं - कम से कम अस्थायी रूप से समस्या का ख्याल रखना प्रतीत होता है।

-(void) releaseBufferForFile:(NSString *) filePath { 
    int bufferId = [self bufferForFile:filePath create:NO]; 
    if (bufferId != kCDNoBuffer) { 
     [soundEngine unloadBuffer:bufferId]; 
     [loadedBuffers removeObjectForKey:filePath]; 
     NSNumber *freedBufferId = [[NSNumber alloc] initWithInt:bufferId]; 
     [freedBufferId autorelease]; 
     [freedBuffers addObject:freedBufferId]; 
    } 
} 
@end 

- (void) interruption:(NSNotification*)notification 
{ 
    NSDictionary *interuptionDict = notification.userInfo; 
      NSNumber* interuptionTypeValue = [dict valueForKey:AVAudioSessionInterruptionTypeKey]; 
    NSUInteger interuptionType = [interuptionTypeValue intValue]; 

    if (interuptionType == AVAudioSessionInterruptionTypeBegan) 
     [self beginInterruption]; 
#if __CC_PLATFORM_IOS >= 40000 
    else if (interuptionType == AVAudioSessionInterruptionTypeEnded) 
     [self endInterruptionWithFlags:(NSUInteger)[interuptionDict valueForKey:AVAudioSessionInterruptionOptionKey]]; 
#else 
    else if (interuptionType == AVAudioSessionInterruptionTypeEnded) 
     [self endInterruption]; 
#endif 
} 

फिर वह बदल दिया:

AVAudioSession *session = [AVAudioSession sharedInstance]; 
session.delegate = self; 
इस के साथ

:

[AVAudioSession sharedInstance]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil]; 

यहाँ लिंक है: http://www.cocos2d-iphone.org/forum/topic/49956

क्या उसने किया CDAudioManger.m फ़ाइल में इस विधि लिखना था

यदि और जब मैं यह कोड कर रहा हूं, तो बेहतर समझने के बाद, मैं टी को संपादित करना सुनिश्चित करूँगा उसकी पोस्ट

+0

मैं CDAudioManager की जरूरत नहीं है इस प्रकार है।एम – CroiOS

+0

आपके द्वारा दिखाए गए लिंक ने उस नए फॉर्म एनएसएनोटिफिकेशन सेंटर का उपयोग करने के साथ मुद्दों के बारे में भी बात की है, आईओएस 5.0 के साथ उस लाइन में खराब एक्सेस त्रुटि फेंकता है ... sooo एक ठोस समाधान क्या होगा? वे सुझाव देते हैं कि आईओएस संस्करण जांचें और तदनुसार कोड फेंक दें। "Poast" के लिए –

+1

+1। – Jonny

0

मैं इस परीक्षण नहीं किया लेकिन इस पोस्ट के अनुसार: http://www.cocos2d-iphone.org/forums/topic/cdaudiomanager-line-402-delegate-is-deprecated/#post-390211

float osVersion = [[UIDevice currentDevice].systemVersion floatValue]; 
if (osVersion >=6.0) 
{ 
[AVAudioSession sharedInstance]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil]; 
} 
else 
{ 
AVAudioSession* session = [AVAudioSession sharedInstance]; 
session.delegate = self; 
} 

अर्थात आईओएस संस्करण के आधार पर अलग कोड रनटाइम फेंक दें।

[AVAudioSession sharedInstance]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil]; 

और मेरे अंगूठे को पार:

अब, मेरे ऐप iOS 6.0+ तो मैं बस के साथ जाना होगा है केवल वैसे भी।

10

इसके बजाय के रूप में से निपटने के लिए प्रतिनिधि उपयोग अधिसूचना का उपयोग करने का

[AVAudioSession sharedInstance]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil]; 

- (void) interruption:(NSNotification*)notification 
    { 
    NSDictionary *interuptionDict = notification.userInfo; 

    NSUInteger interuptionType = (NSUInteger)[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey]; 

    if (interuptionType == AVAudioSessionInterruptionTypeBegan) 
     [self beginInterruption]; 

    else if (interuptionType == AVAudioSessionInterruptionTypeEnded) 
     [self endInterruption]; 
} 
संबंधित मुद्दे