我正在开发一个应检测某种声音频率的应用程序。我的应用基于Pitch Detector。我导入了“音高检测器”示例中的文件,然后修复了代码以接受此新类。我在这里发布我的代码来向您解释我的问题:

ViewController.h

#import <UIKit/UIKit.h>

@class RIOInterface;

@interface ViewController : UIViewController {
    BOOL isListening;
    float currentFrequency;
    RIOInterface *rioRef; // HERE I'M GETTING ISSUE
}
- (IBAction)startListenWatermark:(UIButton *)sender;

@property(nonatomic, assign) RIOInterface *rioRef;
@property(nonatomic, assign) float currentFrequency;
@property(assign) BOOL isListening;

#pragma mark Listener Controls
- (void)startListener;
- (void)stopListener;

 - (void)frequencyChangedWithValue:(float)newFrequency;

@end

ViewController.m
@synthesize isListening;
@synthesize rioRef;
@synthesize currentFrequency;

- (IBAction)startListenWatermark:(UIButton *)sender {
    if (isListening) {
        [self stopListener];
    } else {
        [self startListener];
    }
    isListening = !isListening;
}

- (void)startListener {
    [rioRef startListening:self];
}

- (void)stopListener {
    [rioRef stopListening];
}

- (void)frequencyChangedWithValue:(float)newFrequency {
    NSLog(@"FREQUENCY: %f", newFrequency);
}

在代码中,您可以看到我的问题所在,Xcode表示:Existing instance variable 'rioRef' with assign attribute must be __unsafe_unretained。如果我删除出现此错误的行,则应用程序不会调用[rioRef startListening:self];[rioRef stopListening];方法。

在文件RIOInterface.mm中,第97行出现另一个错误,Xcode建议我将其更改为:
RIOInterface* THIS = (RIOInterface *)inRefCon; --> RIOInterface* THIS = (RIOInterface *)CFBridgingRelease(inRefCon);

它给我在行283上的另一个错误:
callbackStruct.inputProcRefCon = self;

它说:Assigning to 'void' from incompatible type 'RIOInterface *const__strong',所以我看了看网络,找到了以下解决方案:
callbackStruct.inputProcRefCon = (__bridge void*)self;

我不确定这样做是否正确,希望您能帮助我解决此问题,谢谢您的建议。

最佳答案

对于第二个和第三个问题,我通过禁用文件上面上面提供的代码的ARC解决了。对于第一个问题,我通过编写以下代码解决了:
rioRef = [RIOInterface sharedInstance];

关于ios - 使用iPhone检测频率值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21095781/

10-11 22:14