Commits

Jens Alfke committed 60f2b46

* Fixed #9: compilation error with iPhone 3.0 SDK.
* MYBonjourRegistration now allows you to set a TXT dictionary with non-NSData key values; they'll be translated to UTF-8 object descriptions. Useful for NSStrings and NSNumbers.

  • Participants
  • Parent commits 50dc550

Comments (0)

Files changed (4)

File Bonjour/MYBonjourRegistration.m

 }
 
 
++ (NSData*) dataFromTXTRecordDictionary: (NSDictionary*)txtDict {
+    // First translate any non-NSData values into UTF-8 formatted description data:
+    NSMutableDictionary *encodedDict = $mdict();
+    for (NSString *key in txtDict) {
+        id value = [txtDict objectForKey: key];
+        if (![value isKindOfClass: [NSData class]]) {
+            value = [[value description] dataUsingEncoding: NSUTF8StringEncoding];
+        }
+        [encodedDict setObject: value forKey: key];
+    }
+    return [NSNetService dataFromTXTRecordDictionary: encodedDict];
+}
+
+
 - (void) updateTxtRecord {
     [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTxtRecord) object: nil];
     if (self.serviceRef) {
-        NSData *data = [NSNetService dataFromTXTRecordDictionary: _txtRecord];
+        NSData *data = [[self class] dataFromTXTRecordDictionary: _txtRecord];
         Assert(data!=nil, @"Can't convert dictionary to TXT record");
         DNSServiceErrorType err = DNSServiceUpdateRecord(self.serviceRef,
                                                          NULL,

File MYNetwork-iPhone.xcodeproj/project.pbxproj

 			isa = PBXGroup;
 			children = (
 				27D915B90FA8EA85002B0DEC /* Addressing */,
+				278C1B2A0F9F865800954AE1 /* PortMapper */,
 				27D915BA0FA8EA98002B0DEC /* Bonjour */,
-				278C1B2A0F9F865800954AE1 /* PortMapper */,
 				270E9AA30EE61113003F17CA /* TCP */,
 				270E9AAF0EE61113003F17CA /* BLIP */,
 			);

File TCP/TCPConnection.m

 }
 
 
-@synthesize address=_address, isIncoming=_isIncoming, status=_status, delegate=_delegate,
+@synthesize address=_address, isIncoming=_isIncoming, status=_status,
             reader=_reader, writer=_writer, server=_server, openTimeout=_openTimeout;
 
+- (id<TCPConnectionDelegate>) delegate                      {return _delegate;}
+- (void) setDelegate: (id<TCPConnectionDelegate>) delegate  {_delegate = delegate;}
 
 - (NSError*) error
 {

File TCP/TCPListener.m

 }
 
 
-@synthesize delegate=_delegate, port=_port, useIPv6=_useIPv6,
+@synthesize port=_port, useIPv6=_useIPv6,
             bonjourServiceType=_bonjourServiceType, bonjourServiceOptions=_bonjourServiceOptions,
             bonjourPublished=_bonjourPublished, bonjourError=_bonjourError,
             bonjourService=_netService,
             pickAvailablePort=_pickAvailablePort;
 
 
+- (id<TCPListenerDelegate>) delegate                      {return _delegate;}
+- (void) setDelegate: (id<TCPListenerDelegate>) delegate  {_delegate = delegate;}
+
+
 - (NSString*) description
 {
     return $sprintf(@"%@[port %hu]",self.class,_port);