我是 iOS 新手,我正在使用 wit.ai SDK 编写我的第一个应用程序(遵循本指南https://wit.ai/docs/ios/3.1.1/quickstart)。
我可以运行我的应用程序并发送一个命令(我可以在我的 wit.ai 收件箱中找到),但随后应用程序崩溃了。
这是我的代码:
AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
#import "AppDelegate.h"
#import <Wit/Wit.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Wit sharedInstance].accessToken = @"ASW7RE57SOSZLTNBAM6HQ53QAWXSROOI";
[Wit sharedInstance].detectSpeechStop = WITVadConfigDetectSpeechStop;
// Override point for customization after application launch.
return YES;
}
视图控制器.h
#import <UIKit/UIKit.h>
#import <Wit/Wit.h>
@interface ViewController : UIViewController <WitDelegate>
@end
视图控制器.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController {
UILabel *labelView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// set the WitDelegate object
[Wit sharedInstance].delegate = self;
// create the button
CGRect screen = [UIScreen mainScreen].bounds;
CGFloat w = 100;
CGRect rect = CGRectMake(screen.size.width/2 - w/2, 60, w, 100);
WITMicButton* witButton = [[WITMicButton alloc] initWithFrame:rect];
[self.view addSubview:witButton];
// create the label
labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, screen.size.width, 50)];
labelView.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:labelView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)witDidGraspIntent:(NSArray *)outcomes entities:(NSDictionary *)entities body:(NSString *)body error:(NSError*)e {
if (e) {
NSLog(@"[Wit] error: %@", [e localizedDescription]);
return;
}
NSDictionary *firstOutcome = [outcomes objectAtIndex:0];
NSString *intent = [firstOutcome objectForKey:@"intent"];
labelView.text = [NSString stringWithFormat:@"intent = %@", intent];
[self.view addSubview:labelView];
}
@end
这是我得到的错误:
2015-01-12 22:24:21.419 FirstApp [11199:775307] WITVad init 2015-01-12 22:24:27.789 FirstApp [11199:775513] 从回调中排队缓冲区时出错:-66632 2015-01-12 22: 24:27.790 FirstApp [11199:775513] 从回调中排队缓冲区时出错:-66632 2015-01-12 22:24:27.790 FirstApp [11199:775513] 从回调中排队缓冲区时出错:-66632 2015-01-12 22: 24:27.790 FirstApp [11199:775513] 从回调中排队缓冲区时出错:-66632 2015-01-12 22:24:27.790 FirstApp [11199:775513] 从回调中排队缓冲区时出错:-66632 2015-01-12 22: 24:36.442 第一应用 [11199:775307]-[NSCFString objectAtIndex:]:无法识别的选择器发送到实例 0x7f8da0c60c30 2015-01-12 22:24:36.755 FirstApp[11199:775307] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x7f8da0c60c30' *** First throw call stack: ( 0 CoreFoundation 0x0000000105bd0f35 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010548fbb7 objc_exception_throw + 45 2 CoreFoundation 0x0000000105bd804d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x0000000105b3027c ___forwarding_+ 988 4 CoreFoundation 0X0000000105B2FE18 _CF_FORWARDGING_PREP_0 + 120 5 FIRSTAPP 0x0000000000010347778BD- [VIEWCONTROLLER WITDIDGRASPINTITIT:BODY:BODY:BODY:BODY:BODY:BODY:ERROR:ERROR:ERROR:ERROR:] FirstApp 0x000000010347a3f3 -[Wit gotResponse:error:customData:] + 62 9 FirstApp 0x0000000103478549 -[WITRecordingSession gotResponse:error:] + 196 10 FirstApp 0x000000010347b72639-[WITUploader startRequestWithContext:]_block_invoke + 708 11 CFNetwork 0x0000000106781935 __67+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]_block_invoke_2 + 155 12 Foundation 0x000000010360201f __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 7 13 Foundation 0x0000000103541db2 -[NSBlockOperation main] + 98 14 Foundation 0x0000000103524384 -[NSOperationInternal _start:] + 645 15 Foundation 0x0000000103523f93 __NSOQSchedule_f + 184 16 libdispatch.dylib 0x0000000106eec7f4 _dispatch_client_callout + 8 17 libdispatch.dylib 0x0000000106ed58fb _dispatch_main_queue_callback_4CF + 949 18 CoreFoundation 0x0000000105b38fe9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE+ 9 19 CoreFoundation 0x0000000105afbeeb __CFRunLoopRun + 2043 20 CoreFoundation 0x0000000105afb486 CFRunLoopRunSpecific + 470 21 GraphicsServices 0x0000000107f739f0 GSEventRunModal + 161 22 UIKit 0x00000001039d2420 UIApplicationMain + 1282 23 FirstApp 0x0000000103477e53 main + 115 24 libdyld.dylib 0x0000000106f21145 start + 1 25 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib:以 NSException 类型的未捕获异常终止
谢谢你的帮助。