简体   繁体   English

如何正确使用__bridge for ARC

[英]How to use __bridge for ARC correctly

I changed the code shown below into ARC compatible.我将下面显示的代码更改为 ARC 兼容。

I just changed it as Xcode suggested, and it doesn't show error on Xcode. But the code crushes once the event happens.我只是按照 Xcode 的建议更改了它,它在 Xcode 上没有显示错误。但是一旦事件发生,代码就会崩溃。 Does anybody have an idea to fix this?有没有人有解决这个问题的想法?

I'm not sure if this crush happens because of acapela SDK, or not.我不确定这种迷恋是不是因为 acapela SDK 而发生的。

This is non ARC code, it works fine.这是非 ARC 代码,它工作正常。

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];.这是 ARC 兼容的,但它压倒了 [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我正在使用 Acapela 音频 SDK,音频中断代码显示在 9.Interruptions of this 8825587763888.http://www.ecometrixem.com/cms-assets/documents/44729-919017.acapela-for-iphone.8825068658688

This is the screenshot for the crush.这是暗恋的截图。在此处输入图像描述

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];
    }
}

You need something like this:你需要这样的东西:

id asObject = (__bridge id) (*(void **) ptr);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM