我正在开发一款应用程序,该应用程序应检测某种声音的频率。我基于我的应用程序Pitch Detector。我导入了Pitch Detector示例中的文件,然后我修复了我的代码以接受这个新类。我在这里发布我的代码解释你我的问题:使用iPhone检测频率值
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;
我不确定是否适合这样做,我希望你能帮助我解决这个问题,谢谢你的建议。
什么'callbackStruct.inputProcRefCon'声明:对于第一个问题,我写这段代码解决了吗?如果这是一个C回调机制,那么你不会传递它一个Objective-C对象,你会。 – trojanfoe
我想是这样,我也没写的这部分代码,它是在图书馆'RIOInterface' – lucgian841
尝试删除行:RIOInterface * rioRef;还有@synthesize rioRef; – Greg