Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ DerivedData/
.netrc
*.xcodeproj
!Examples/iOSDemo/iOSDemo.xcodeproj
!Examples/iOSDemoObjC/iOSDemoObjC.xcodeproj
_codeql_detected_source_root
408 changes: 408 additions & 0 deletions Examples/iOSDemoObjC/iOSDemoObjC.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Examples/iOSDemoObjC/iOSDemoObjC/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// AppDelegate.h
// iOSDemoObjC
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
25 changes: 25 additions & 0 deletions Examples/iOSDemoObjC/iOSDemoObjC/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// AppDelegate.m
// iOSDemoObjC
//

#import "AppDelegate.h"
#import "MainViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

MainViewController *mainVC = [[MainViewController alloc] initWithStyle:UITableViewStyleInsetGrouped];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mainVC];

self.window.rootViewController = nav;
[self.window makeKeyAndVisible];

return YES;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
12 changes: 12 additions & 0 deletions Examples/iOSDemoObjC/iOSDemoObjC/MainViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// MainViewController.h
// iOSDemoObjC
//
// Navigation hub — equivalent of ContentView.swift in the Swift demo.
//

#import <UIKit/UIKit.h>

@interface MainViewController : UITableViewController

@end
107 changes: 107 additions & 0 deletions Examples/iOSDemoObjC/iOSDemoObjC/MainViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// MainViewController.m
// iOSDemoObjC
//

#import "MainViewController.h"
#import "StreamBufferDemoViewController.h"
#import "SSEParserDemoViewController.h"
#import "UTF8SafetyDemoViewController.h"
#import "SocketConnectionDemoViewController.h"

typedef NS_ENUM(NSInteger, DemoSection) {
DemoSectionCore = 0,
DemoSectionSocket,
DemoSectionCount
};

@implementation MainViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"NWAsyncSocket ObjC Demo";
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return DemoSectionCount;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case DemoSectionCore: return @"Core Components";
case DemoSectionSocket: return @"Socket";
default: return nil;
}
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case DemoSectionCore: return 3;
case DemoSectionSocket: return 1;
default: return 0;
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

UIListContentConfiguration *config = [UIListContentConfiguration cellConfiguration];

if (indexPath.section == DemoSectionCore) {
switch (indexPath.row) {
case 0:
config.text = @"StreamBuffer";
config.image = [UIImage systemImageNamed:@"arrow.left.arrow.right"];
break;
case 1:
config.text = @"SSE Parser";
config.image = [UIImage systemImageNamed:@"antenna.radiowaves.left.and.right"];
break;
case 2:
config.text = @"UTF-8 Safety";
config.image = [UIImage systemImageNamed:@"textformat"];
break;
}
} else {
config.text = @"Socket Connection";
config.image = [UIImage systemImageNamed:@"network"];
}

cell.contentConfiguration = config;
return cell;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];

UIViewController *vc = nil;
if (indexPath.section == DemoSectionCore) {
switch (indexPath.row) {
case 0:
vc = [[StreamBufferDemoViewController alloc] initWithStyle:UITableViewStyleGrouped];
break;
case 1:
vc = [[SSEParserDemoViewController alloc] initWithStyle:UITableViewStyleGrouped];
break;
case 2:
vc = [[UTF8SafetyDemoViewController alloc] initWithStyle:UITableViewStyleGrouped];
break;
}
} else {
vc = [[SocketConnectionDemoViewController alloc] initWithStyle:UITableViewStyleGrouped];
}

if (vc) {
[self.navigationController pushViewController:vc animated:YES];
}
}

@end
40 changes: 40 additions & 0 deletions Examples/iOSDemoObjC/iOSDemoObjC/SocketManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// SocketManager.h
// iOSDemoObjC
//
// Encapsulates GCDAsyncSocket operations — equivalent of SocketManager.swift
// in the Swift demo.
//

#import <Foundation/Foundation.h>
#import "GCDAsyncSocket.h"
#import "GCDAsyncSocketDelegate.h"

NS_ASSUME_NONNULL_BEGIN

/// Notification posted when SocketManager state changes (connection, logs, data).
extern NSNotificationName const SocketManagerDidUpdateNotification;

@interface SocketManager : NSObject

@property (nonatomic, readonly) BOOL isConnected;
@property (nonatomic, readonly, copy) NSArray<NSString *> *logs;
@property (nonatomic, readonly, copy) NSData *receivedData;
@property (nonatomic, readonly, copy) NSString *receivedText;
@property (nonatomic, readonly, copy) NSArray<NWSSEEvent *> *sseEvents;

- (void)connectToHost:(NSString *)host
port:(uint16_t)port
useTLS:(BOOL)useTLS
enableSSE:(BOOL)enableSSE
enableStreaming:(BOOL)enableStreaming;

- (void)sendText:(NSString *)text;
- (void)sendData:(NSData *)data;
- (void)readData;
- (void)disconnect;
- (void)clearAll;

@end

NS_ASSUME_NONNULL_END
Loading