[英]SIGBART error trying to connect to a TCP server on iOS
我正在使用CocoaAsyncSocket庫嘗試從我的iOS設備到某處的服務器建立簡單的TCP連接,現在我正試圖僅嘗試檢查設置並連接到遠程服務器。 IP地址。
下載庫之后,我打開了以下項目:
GCD-> Xcode-> ConnectTest->移動
我已經打開了這個示例,因為我認為這是最簡單的示例,並展示了我需要它執行的操作。 我已經在編輯器中運行了程序而沒有碰到代碼,它可以按預期工作。 但是,當我將代碼帶到程序中時,出現以下日志錯誤:
-[BTLECentralViewController window]: unrecognized selector sent to instance 0x17e2c460
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BTLECentralViewController window]: unrecognized selector sent to instance 0x17e2c460'
*** First throw call stack:
(0x314a0e8b 0x3b79a6c7 0x314a47b7 0x314a2f55 0x313f1e98 0xc5e89 0x33c2ab3b 0x33c2a8f9 0x33db75a3 0x33cd51df 0x33cd4fe9 0x33cd4f7d 0x33c26533 0x338adf43 0x338a9767 0x338a95f9 0x338a900d 0x338a8e1f 0x338a2b4d 0x3146bf71 0x314698ff 0x31469c4b 0x313d4541 0x313d4323 0x3610b2eb 0x33c8b1e5 0xc4bb9 0x3bc93ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
與我從他們那里獲取代碼一樣,在他們的AppDelegate類中建立了連接。 我已經把它放在要激活它的視圖控制器中。
所以現在我的viewcontroller.h看起來像這樣:
#import <UIKit/UIKit.h>
@class GCDAsyncSocket;
@class BTLECentralViewController;
@interface BTLECentralViewController : UIViewController <UIApplicationDelegate>
{
GCDAsyncSocket *async_socket;
}
@property (nonatomic) IBOutlet BTLECentralViewController *view_controller;
@end
隨附的.m文件如下。 我將只發布已為其添加新代碼的代碼方法。 我不會浪費時間參加整個課堂。
#import "GCDAsyncSocket.h"
#if USE_SECURE_CONNECTION
#define HOST @"www.paypal.com"
#define PORT 443
#else
#define HOST @"google.com";
#define PORT 80
#endif
- (void)viewDidLoad
{
[super viewDidLoad];
// Start up the CBCentralManager
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
dispatch_queue_t mainQueue = dispatch_get_main_queue();
async_socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:mainQueue];
#if USE_SECURE_CONNECTION
{
NSString *host = HOST;
uint16_t port = PORT;
DDLogInfo(@"Connecting to \"%@\" on port %hu...", host, port);
self.viewController.label.text = @"Connecting...";
NSError *error = nil;
if (![asyncSocket connectToHost:@"www.paypal.com" onPort:port error:&error])
{
DDLogError(@"Error connecting: %@", error);
self.viewController.label.text = @"Oops";
}
}
#else
{
NSString *host = HOST;
uint16_t port = PORT;
// DDLogInfo(@"Connecting to \"%@\" on port %hu...", host, port);
_estimote_3_label.text = @"Connecting...";
NSError *error = nil;
if (![async_socket connectToHost:host onPort:port error:&error])
{
// DDLogError(@"Error connecting: %@", error);
_estimote_3_label.text = @"Oops";
}
// You can also specify an optional connect timeout.
// NSError *error = nil;
// if (![asyncSocket connectToHost:host onPort:80 withTimeout:5.0 error:&error])
// {
// DDLogError(@"Error connecting: %@", error);
// }
}
#endif
// Normal iOS stuff...
self.window.rootViewController = self.view_controller;
[self.window makeKeyAndVisible];
}
如我所說,我的希望是在調試日志中出現一個“已連接”字符串。 但是,當我運行它時,我得到了調試日志錯誤,並粘貼在頂部,而我的主類中出現了SIGBART錯誤,如下所示:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
任何有使用該庫的更多經驗的人都可以幫助我,告訴我我做錯了什么,為什么會出現這些錯誤?
請注意,在編輯器中,示例項目正常運行,並且在我的iPhone 5上運行正常。 只是在我將相關代碼帶到我的項目中時,我才遇到這些問題。
BTLECentralViewController和UIViewController沒有您要使用的window屬性:
self.window.rootViewController = self.view_controller;
[self.window makeKeyAndVisible];
我認為那應該放在AppDelegate(UIResponder)類中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.