• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting Computer Name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting Computer Name


  • Subject: Re: Getting Computer Name
  • From: "Paul Sanders" <email@hidden>
  • Date: Sun, 20 Jun 2010 11:23:09 +0100

I use #1 and it works fine for me.  Note that SCDynamicStoreCopyComputerName might return NULL, and don't forget to CFRelease temp.

In the case of #1, what is the NSLog statement that is failing?  And I take it that name hasn't been autoreleased before you log it - it will only survive until the current autorelease pool 'pops'.  You can look at name (and probably temp, but I'm not sure) in the debugger, of course.

Regards,

Paul Sanders.

----- Original Message -----
From: Steve Steinitz
To: email@hidden
Sent: Sunday, June 20, 2010 11:10 AM
Subject: Getting Computer Name


Hello,

I've found several examples of getting the computer Name but
some give warnings about making a pointer from an integer and
they all fail with signal EXC_BAD_ACCESS here

     objc_msgSend_vtable5
     _NSDescriptionWithLocaleFunc
     _CFStringAppendFormatAndArgumentsAux
     _CFStringCreateWithFormatAndArgumentsAux
     _CFLogvEx
     NSLogv
     NSLog

Here are three examples I've tried:

1.  CFStringRef temp = SCDynamicStoreCopyComputerName (NULL, NULL);
     NSString * name = [NSString stringWithString: temp];
     return name;

2.  CFStringEncoding encoding = kCFStringEncodingUTF8;
     CFStringRef name = SCDynamicStoreCopyComputerName (NULL, &encoding);
     return name;

3.  #import <SystemConfiguration/SCDynamicStore.h>

     SCDynamicStoreContext context = {0, NULL, NULL, NULL};
     SCDynamicStoreRef store = SCDynamicStoreCreate (kCFAllocatorDefault,
                                                     CFSTR("testStrings"),
                                                     NULL,
                                                     &context);
     NSLog(@"SCDynamicStoreCopyLocalHostName() = %@",
             SCDynamicStoreCopyLocalHostName(store));

According to the docs CFStringRef is toll-free-bridged with
NSString and so interchangeable.  The authors of the examples
cite no issues.  Could I have done something to my project to
break toll-free bridging?  I confess, I haven't thought about
toll-free bridging since the WebObjects days.

Thanks for any ideas,

Steve
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Getting Computer Name
      • From: Steve Steinitz <email@hidden>
References: 
 >Getting Computer Name (From: Steve Steinitz <email@hidden>)

  • Prev by Date: Getting Computer Name
  • Next by Date: Re: Getting Computer Name
  • Previous by thread: Getting Computer Name
  • Next by thread: Re: Getting Computer Name
  • Index(es):
    • Date
    • Thread