Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use __bridge for ARC correctly

I changed the code shown below into ARC compatible.

I just changed it as Xcode suggested, and it doesn't show error on Xcode. But the code crushes once the event happens. Does anybody have an idea to fix this?

I'm not sure if this crush happens because of acapela SDK, or not.

This is non ARC code, it works fine.

void MyInterruptionListener(void *inClientData, UInt32 inInterruptionState) {

    AcapelaSpeech* anAcapelaSpeech = *(AcapelaSpeech**)inClientData;

    if (inInterruptionState == kAudioSessionBeginInterruption) {

        [anAcapelaSpeech setActive:NO];
        status = AudioSessionSetActive(NO);
    }
    if (inInterruptionState == kAudioSessionEndInterruption) {

        status = AudioSessionSetActive(YES);
        [anAcapelaSpeech setActive:YES];
    }
}

This is ARC compatible, but it crushes on [anAcapelaSpeech setActive:NO];.

void MyInterruptionListener(void *inClientData, UInt32 inInterruptionState) {

    AcapelaSpeech* anAcapelaSpeech = (__bridge_transfer AcapelaSpeech*)inClientData;

    if (inInterruptionState == kAudioSessionBeginInterruption) {

        [anAcapelaSpeech setActive:NO];
        AudioSessionSetActive(NO);
    }
    if (inInterruptionState == kAudioSessionEndInterruption) {

        AudioSessionSetActive(YES);
        [anAcapelaSpeech setActive:YES];
    }
}

Additional info. I'm using Acapela audio SDK, audio interruption code is shown on the 9.Interruptions of this PDF. http://www.ecometrixem.com/cms-assets/documents/44729-919017.acapela-for-iphone.pdf

This is the screenshot for the crush. enter image description here

SOLVED This code works, thanks.

void MyInterruptionListener(void *inClientData, UInt32 inInterruptionState) {

    AcapelaSpeech *anAcapelaSpeech = (__bridge id) (*(void **) inClientData);

    if (inInterruptionState == kAudioSessionBeginInterruption) {

        [anAcapelaSpeech setActive:NO];
        AudioSessionSetActive(NO);
    }
    if (inInterruptionState == kAudioSessionEndInterruption) {

        AudioSessionSetActive(YES);
        [anAcapelaSpeech setActive:YES];
    }
}
like image 358
Non Umemoto Avatar asked Apr 06 '12 23:04

Non Umemoto


1 Answers

You need something like this:

id asObject = (__bridge id) (*(void **) ptr);
like image 105
Richard J. Ross III Avatar answered Oct 09 '22 14:10

Richard J. Ross III