使用「自我」我試圖通過使TriggerIO本地插件播放語音音頻上的的iPodMusicPlayer
頂部,但我無法訪問self
對象。在@implementation
#import "alert_API.h"
@implementation alert_API
+ (void)play:(ForgeTask*)task text:(NSString *)filename {
NSURL* url = [[NSBundle mainBundle] URLForResource:@"Rondo_Alla_Turka_Short" withExtension:@"aiff"];
NSAssert(url, @"URL is valid.");
NSError* error = nil;
/* ERROR: /Users/gsquare567/forge-workspace/plugins/audio/inspector/ios-inspector/ForgeModule/alert/alert_API.m:45:13: Member reference type 'struct objc_class *' is a pointer; maybe you meant to use '->'? */
self->player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
/* ERROR: /Users/gsquare567/forge-workspace/plugins/audio/inspector/ios-inspector/ForgeModule/alert/alert_API.m:45:13: Incomplete definition of type 'struct objc_class' */
if(!self.player)
{
NSLog(@"Error creating player: %@", error);
}
[task success:nil];
}
@end
,該場所被alert_API.h
定義:
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface alert_API : NSObject
@property (nonatomic, strong) AVAudioPlayer* player;
+ (void)play:(ForgeTask*)task text:(NSString *)filename;
@end
什麼我需要在這裏做的是能夠在我的API訪問player
財產?
謝謝!
這是一個類方法,而不是一個實例方法。在類方法中,'self'指的是'class',而不是任何實例。您不能從類方法訪問ivars。在類方法中,'self'可以用來調用其他類方法,但基本上就是這樣。 – rmaddy 2013-04-11 14:32:53