我正在开发一款可以检测特定声音频率的应用。我的应用基于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;
我不确定这样做是否正确,我希望你能帮助我解决这个问题,谢谢你的建议。
答案 0 :(得分:3)
对于我解决的第二个和第三个问题,我通过禁用ARC来获取上面提供的代码的文件。对于我通过编写此代码解决的第一个问题:
rioRef = [RIOInterface sharedInstance];