使用iPhone检测频率值

luc*_*841 5 objective-c ios

我正在开发一款可以检测特定声音频率的应用.我的应用程序基于Pitch Detector.我导入了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
Run Code Online (Sandbox Code Playgroud)

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);
}
Run Code Online (Sandbox Code Playgroud)

在代码中你可以看到我的问题在哪里,Xcode说:Existing instance variable 'rioRef' with assign attribute must be __unsafe_unretained.如果我删除,让行这errore应用程序不调用方法[rioRef startListening:self];[rioRef stopListening];.

在文件中,RIOInterface.mm我在第97行收到另一个错误,Xcode建议我将其更改为:

RIOInterface* THIS = (RIOInterface *)inRefCon; --> RIOInterface* THIS = (RIOInterface *)CFBridgingRelease(inRefCon);
Run Code Online (Sandbox Code Playgroud)

它给了我283行的另一个错误:

callbackStruct.inputProcRefCon = self;
Run Code Online (Sandbox Code Playgroud)

它告诉我这个:Assigning to 'void' from incompatible type 'RIOInterface *const__strong'所以我查看了网络,我发现了这个解决方案:

callbackStruct.inputProcRefCon = (__bridge void*)self;
Run Code Online (Sandbox Code Playgroud)

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

luc*_*841 3

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

rioRef = [RIOInterface sharedInstance];