【发布时间】:2016-02-08 20:33:26
【问题描述】:
我在尝试在 Swift 中集成代码时遇到了 Quickblox 问题。
以下代码在 Objective-C 中运行没有任何错误
AppDellgate.m 文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[QBSettings setApplicationID:kApplicationID];
[QBSettings setAuthKey:kAuthKey];
[QBSettings setAuthSecret:kAuthSecret];
[QBSettings setAccountKey:kAcconuntKey];
[[GeoDataManager instance] fetchLatestCheckIns];
return YES;
}
GeoDataManager.m 文件
@implementation GeoDataManager
+ (instancetype)instance
{
static GeoDataManager *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [self new];
});
return instance;
}
- (void)fetchLatestCheckIns
{
QBLGeoDataFilter* filter = [QBLGeoDataFilter new];
filter.lastOnly = YES;
filter.sortBy = GeoDataSortByKindCreatedAt;
QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:70];
[QBRequest geoDataWithFilter:filter page:page successBlock:^(QBResponse *response, NSArray *objects, QBGeneralResponsePage *page) {
[[DataManager sharedDataManager] saveCheckIns:objects];
} errorBlock:^(QBResponse *response) {
NSLog(@"Error = %@", response.error);
}];
}
但是当我尝试从下面的代码中调用我的 Swift 基础项目中的相同方法时
Swift AppDelegate。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Set QuickBlox credentials (You must create application in admin.quickblox.com).
QBSettings.setApplicationID(kQBApplicationID)
QBSettings.setAuthKey(kQBAuthKey)
QBSettings.setAuthSecret(kQBAuthSecret)
QBSettings.setAccountKey(kQBAccountKey)
GeoDataManager .instance().fetchLatestCheckIns()
return true
}
我收到未捕获的异常“NSInvalidArgumentException”,原因: '+[QBRequest geoDataWithFilter:page:successBlock:errorBlock:]: 无法识别的选择器发送到类。
我已经添加了 GeoDataManager 并为其创建了一个桥接头。
谁能帮我解决我做错了什么?任何想法或建议都会很棒。
【问题讨论】: