diff --git a/Peertalk macOS Example/PTAppDelegate.m b/Peertalk macOS Example/PTAppDelegate.m index ccc43eb..18f472f 100644 --- a/Peertalk macOS Example/PTAppDelegate.m +++ b/Peertalk macOS Example/PTAppDelegate.m @@ -229,7 +229,7 @@ - (void)startListeningForDevices { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserverForName:PTUSBDeviceDidAttachNotification object:PTUSBHub.sharedHub queue:nil usingBlock:^(NSNotification *note) { - NSNumber *deviceID = [note.userInfo objectForKey:@"DeviceID"]; + NSNumber *deviceID = [note.userInfo objectForKey:PTUSBHubNotificationKeyDeviceID]; //NSLog(@"PTUSBDeviceDidAttachNotification: %@", note.userInfo); NSLog(@"PTUSBDeviceDidAttachNotification: %@", deviceID); @@ -237,14 +237,14 @@ - (void)startListeningForDevices { if (!self->connectingToDeviceID_ || ![deviceID isEqualToNumber:self->connectingToDeviceID_]) { [self disconnectFromCurrentChannel]; self->connectingToDeviceID_ = deviceID; - self->connectedDeviceProperties_ = [note.userInfo objectForKey:@"Properties"]; + self->connectedDeviceProperties_ = [note.userInfo objectForKey:PTUSBHubNotificationKeyProperties]; [self enqueueConnectToUSBDevice]; } }); }]; [nc addObserverForName:PTUSBDeviceDidDetachNotification object:PTUSBHub.sharedHub queue:nil usingBlock:^(NSNotification *note) { - NSNumber *deviceID = [note.userInfo objectForKey:@"DeviceID"]; + NSNumber *deviceID = [note.userInfo objectForKey:PTUSBHubNotificationKeyDeviceID]; //NSLog(@"PTUSBDeviceDidDetachNotification: %@", note.userInfo); NSLog(@"PTUSBDeviceDidDetachNotification: %@", deviceID); diff --git a/peertalk/PTUSBHub.h b/peertalk/PTUSBHub.h index 2277fdd..5e5b8fe 100644 --- a/peertalk/PTUSBHub.h +++ b/peertalk/PTUSBHub.h @@ -18,7 +18,7 @@ // }; // } // -FOUNDATION_EXPORT NSString * const PTUSBDeviceDidAttachNotification; +FOUNDATION_EXPORT NSNotificationName const PTUSBDeviceDidAttachNotification NS_SWIFT_NAME(deviceDidAttach); // PTUSBDeviceDidDetachNotification // Posted when a device has been detached. @@ -28,7 +28,12 @@ FOUNDATION_EXPORT NSString * const PTUSBDeviceDidAttachNotification; // MessageType = Detached; // } // -FOUNDATION_EXPORT NSString * const PTUSBDeviceDidDetachNotification; +FOUNDATION_EXPORT NSNotificationName const PTUSBDeviceDidDetachNotification NS_SWIFT_NAME(deviceDidDetach); + +typedef NSString * PTUSBHubNotificationKey NS_TYPED_ENUM; +FOUNDATION_EXPORT PTUSBHubNotificationKey const PTUSBHubNotificationKeyDeviceID NS_SWIFT_NAME(deviceID); +FOUNDATION_EXPORT PTUSBHubNotificationKey const PTUSBHubNotificationKeyMessageType NS_SWIFT_NAME(messageType); +FOUNDATION_EXPORT PTUSBHubNotificationKey const PTUSBHubNotificationKeyProperties NS_SWIFT_NAME(properties); // NSError domain FOUNDATION_EXPORT NSString * const PTUSBHubErrorDomain; diff --git a/peertalk/PTUSBHub.m b/peertalk/PTUSBHub.m index 8b6c8fe..eb8a838 100644 --- a/peertalk/PTUSBHub.m +++ b/peertalk/PTUSBHub.m @@ -106,13 +106,16 @@ static void usbmux_packet_free(usbmux_packet_t *upacket) { } -NSString * const PTUSBDeviceDidAttachNotification = @"PTUSBDeviceDidAttachNotification"; -NSString * const PTUSBDeviceDidDetachNotification = @"PTUSBDeviceDidDetachNotification"; +NSNotificationName const PTUSBDeviceDidAttachNotification = @"PTUSBDeviceDidAttachNotification"; +NSNotificationName const PTUSBDeviceDidDetachNotification = @"PTUSBDeviceDidDetachNotification"; + +PTUSBHubNotificationKey const PTUSBHubNotificationKeyDeviceID = @"DeviceID"; +PTUSBHubNotificationKey const PTUSBHubNotificationKeyMessageType = @"MessageType"; +PTUSBHubNotificationKey const PTUSBHubNotificationKeyProperties = @"Properties"; static NSString *kPlistPacketTypeListen = @"Listen"; static NSString *kPlistPacketTypeConnect = @"Connect"; - // Represents a channel of communication between the host process and a remote // (device) system. In practice, a PTUSBChannel is connected to a usbmuxd // endpoint which is configured to either listen for device changes (the @@ -232,7 +235,7 @@ - (void)connectToDevice:(NSNumber*)deviceID port:(int)port onStart:(void(^)(NSEr NSDictionary *packet = [PTUSBChannel packetDictionaryWithPacketType:kPlistPacketTypeConnect payload:[NSDictionary dictionaryWithObjectsAndKeys: - deviceID, @"DeviceID", + deviceID, PTUSBHubNotificationKeyDeviceID, [NSNumber numberWithInt:port], @"PortNumber", nil]]; @@ -245,7 +248,7 @@ - (void)connectToDevice:(NSNumber*)deviceID port:(int)port onStart:(void(^)(NSEr - (void)handleBroadcastPacket:(NSDictionary*)packet { - NSString *messageType = [packet objectForKey:@"MessageType"]; + NSString *messageType = [packet objectForKey:PTUSBHubNotificationKeyMessageType]; if ([@"Attached" isEqualToString:messageType]) { [[NSNotificationCenter defaultCenter] postNotificationName:PTUSBDeviceDidAttachNotification object:self userInfo:packet]; @@ -279,12 +282,12 @@ + (NSDictionary*)packetDictionaryWithPacketType:(NSString*)messageType payload:( if (bundleName) { packet = [NSDictionary dictionaryWithObjectsAndKeys: - messageType, @"MessageType", + messageType, PTUSBHubNotificationKeyMessageType, bundleName, @"ProgName", bundleVersion, @"ClientVersionString", nil]; } else { - packet = [NSDictionary dictionaryWithObjectsAndKeys:messageType, @"MessageType", nil]; + packet = [NSDictionary dictionaryWithObjectsAndKeys:messageType, PTUSBHubNotificationKeyMessageType, nil]; } if (payload) { @@ -345,7 +348,7 @@ - (BOOL)openOnQueue:(dispatch_queue_t)queue error:(NSError**)error onEnd:(void(^ // Connect socket struct sockaddr_un addr; addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, "/var/run/usbmuxd"); + strcpy(addr.sun_path, "/private/var/run/usbmuxd"); socklen_t socklen = sizeof(addr); if (connect(fd, (struct sockaddr*)&addr, socklen) == -1) { if (error) *error = [[NSError alloc] initWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil];