ios - 使用 iPhone 检测频率值

标签 ios objective-c

我正在开发一款应能检测特定声音频率的应用。我的应用基于 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

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/

相关文章:

ios - 调试时如何从命令行启动iOS应用?

ios - 有没有办法检查照片是否是在该 iPhone 上拍摄的?

ios - iOS 版 Audiobus 如何工作?

ios - 在表格 View 单元格上单击打开 URL

ios - 用 NSDictionary 填充数组

ios - Swift 5 : Why swift 5 update ask to forcibly unwrap the label. 字体?

ios - 将 fetchedResultsController 与 swift3 一起使用

objective-c - 使用 UITableView 和条件时字体颜色设置不正确

ios - 如何使用storyBoard设置MFSlideviewcontroller的 View Controller ?

iphone - 在 iPhone 应用程序中播放音频