我刚刚开始将一个Android应用程序移植到iOS上,并且遇到了一个主要的障碍,尽管我在搜索许多类似的问题时仍然无法弄清楚.
我试图遵循CastVideos示例中实现的模式,其中GoogleCast API封装在我调用的单例类中CastManager
.要使用我的单例类,我#import "CastManager.h"
在AppDelegate.m中.然后在CastManager.h中,我#import <GoogleCast/GoogleCast.h>
可以使用它的类和协议作为CastManager的公共接口的一部分.但是,因为我在CastManager.m和AppDelegate.m中导入CastManager.h,所以链接器正在从GoogleCast框架中查找重复的符号.
这是我的CastManager.h:
#import <GoogleCast/GoogleCast.h>
#import <Foundation/Foundation.h>
@interface CastManager : NSObject
@property(nonatomic, strong) GCKDeviceScanner *deviceScanner;
+ (instancetype)sharedCastManager;
@end
Run Code Online (Sandbox Code Playgroud)
和相应的CastManager.m:
#import "CastManager.h"
@implementation CastManager
+ (instancetype)sharedCastManager {
NSLog(@"sharedCastManager");
static CastManager *singleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
singleton = [[self alloc] init];
});
return singleton;
}
- (instancetype)init {
NSLog(@"init()");
if (self = [super init]) {
self.deviceScanner = [[GCKDeviceScanner alloc] init];
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
这是我的AppDelegate.m的主要部分:
#import "AppDelegate.h" …
Run Code Online (Sandbox Code Playgroud)