Detect the name of wireless network - iphone

Is it possible to run a method that will return the name of the wireless network that the user is connected to? Inside of my app I want to be able to return the name of the wireless network that the user is connected to.

This worked perfect for me:
#import <SystemConfiguration/CaptiveNetwork.h>
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
// NSLog(#"SSID: %#",CFDictionaryGetValue(myDict, kCNNetworkInfoKeySSID));
NSString *networkName = CFDictionaryGetValue(myDict, kCNNetworkInfoKeySSID);
if ([networkName isEqualToString:#"Hot Dog"])
{
self.storeNameController = [[StoreDataController alloc] init];
[self.storeNameController addStoreNamesObject];
}
else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Connection Failed"
message: #"Please connect to the Hot Dog network and try again"
delegate: self
cancelButtonTitle: #"Close"
otherButtonTitles: nil];
[alert show];

From Developer.apple , you can use CNCopyCurrentNetworkInfo
It Returns the current network info for a given network interface.
CFDictionaryRef CNCopyCurrentNetworkInfo (
CFStringRef interfaceName
);
It contains a dictionary that containing the interface’s current network info. Ownership follows the Create Rule.
Note:Available in iOS 4.1 and later.
EXAMPLE:
This example will work fine in real device, It may crash in simulator.
Add SystemConfiguration.framework
Import CaptiveNetwork header same as below
#import <SystemConfiguration/CaptiveNetwork.h>
Then write the below code.
CFArrayRef myArray = CNCopySupportedInterfaces();
// Get the dictionary containing the captive network infomation
CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
NSLog(#"Information of the network we're connected to: %#", captiveNtwrkDict);
NSDictionary *dict = (__bridge NSDictionary*) captiveNtwrkDict;
NSString* ssid = [dict objectForKey:#"SSID"];
NSLog(#"network name: %#",ssid);
or
Using Bonjour, the application both advertises itself on the local network and displays a list of other instances of this application on the network
See the sample Witap application

The BAD NEWS: 'CNCopyCurrentNetworkInfo' is deprecated: first deprecated in iOS 9.0 - For captive network applications, this has been completely replaced by <NetworkExtension/NEHotspotHelper.h>. For other applications, there is no direct replacement. Please file a bug describing your use of this API to that we can consider your requirements as this situation evolves.
The GOOD NEWS: although deprecated, it still works in iOS 9, AND it has been un-deprecated in iOS 10.
It still works in iOS 13, but only if the app implements Location Services and the user authorizes their usage.

Related

connecting to cB-OLP425 in background iphone app

I am trying to connect to a cB-OLP425 ble device while the app is in the background. I have done everything I can find to do on the web. I have set the advertising interval to 20ms like this in connect blue's cb.demo.c using IAR embededWorkbench.
void gapSetAlwaysAdvertising(void)
{
uint8 advertising_enable = TRUE;
uint16 desired_min_advertising_interval = 20; **//I'M ASSUMING THIS IS 20ms changed it from 1600**
int16 desired_max_advertising_interval = 2500;
uint8 advertData[] = 0x02, //length of first data structure (2 bytes excluding length byte)
**//I'm thinking I need to change this to 0x05 which is 30 sec. am I correct**
GAP_ADTYPE_FLAGS, //AD Type = Flags
GAP_ADTYPE_FLAGS_GENERAL | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED
};
I have made the so that it connects only to one particular module by renaming it's local name and then only allowing to connect to that name.
Somewhere I read that this may be a problem in that in background this may be left off?
I use this code for finding module
- (id)init
{
if ((self = [super init]))
{
self.characteristicsCBUUID = [NSMutableDictionary new];
self.myPeripherals = [NSMutableArray new];
manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
return self;
}
- (void)startScan
{
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[manager scanForPeripheralsWithServices:self.myPeripherals options:options];
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(#"Did discover peripheral. peripheral: %# rssi: %#, UUID: %# advertisementData: %# ", peripheral, RSSI, peripheral.UUID, advertisementData);
NSDictionary *dataDict = [NSDictionary dictionaryWithObject:#"Specialname" forKey:#"kCBAdvDataLocalName" ];
if(![self.myPeripherals containsObject:peripheral])
[self.myPeripherals addObject:peripheral];
if ([advertisementData isEqualToDictionary:dataDict]) {
[manager retrievePeripherals:[NSArray arrayWithObject:(id) peripheral.UUID]];
}
}
I have added the correct information into the apps Plist for functionality in background mode.
not however audio since I heard Apple won't approve this if it is just added to keep app from going to sleep.
Does anyone have any suggestions or see where I need to change/add anything. I'm starting to get frustrated.
Thanks for any and all help
For background mode central, use plist key "bluetooth-central" like this:
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
</array>
Note that in background mode, you can only scan for devices with pre-defined UUID services.
Also, when getting peripheral advertisements in background mode, you do not always have the "local-name" part of the advertisement data.
Actually, in my peripheral BTLE app, when in background mode, the advertising does not include the "local-name".
What I did to ensure that I connect my central with the proper peripheral is I generated a UUID from my central, stored it in my peripheral, with some sort of custom pairing procedure.
This way, my peripheral app in background mode advertises the service UUID previously generated by my central, and the central can recognize it even without its local-name.

Issue in loading http://www.google.com url in iOS app

I was using the following code for checking the internet connection in my first iOS app (almost 3 years ago).
NSError *err = nil;
NSStringEncoding encoding;
NSString * connectionstring = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://www.google.com"] usedEncoding:&encoding error:&err];
if(connectionstring.length ==0)
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error Occured" message:#"No Internet Connection." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
// loading another screen
}
The problem is in India and US it is going into the else condition but in Belgium it is going into the if condition and throwing the error. So are there any restrictions for Google in Belgium?
If it is tagged incorrectly please guide me. In my current versions solved this issue by using Rechability classes to check this . Just I wanted to know about it . Thanks in advance.
As a first step, look at the encoding.
You can log the encoding right after the connectionstring is created by inserting
NSLog(#"encoding: %#", [NSString localizedNameOfStringEncoding:encoding]);
into your code.
For further debugging, you could try loading the url into an NSData object first, then inspect the data and finally create a NSString from the data.
Alternative solution: To check internet connection Use Reachability class provided by apple.
Download Apple Sample Here, add Reachability class to your project.
- (BOOL)isConnected
{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [reachability currentReachabilityStatus];
return !(networkStatus == NotReachable);
}
Instead of using google.com use any local client server test url for internet checking it will also be very fast responsive comparatively of any other way of internet validation.

iOS unique user identifier [duplicate]

This question already has answers here:
UIDevice uniqueIdentifier deprecated - What to do now?
(32 answers)
Closed 8 years ago.
I'm writting an application for iphone, which communicates with my server using REST. The main problem is, I need to identify user somehow. Not so long ago, we were allowed to use UDID, but now its not allowed anymore. So what should I use instead? I need some kind of identifier on iphone, so user will delete application, install it again, and he will get same id.
I used CFUUIDCreate() to create a UUID:
+ (NSString *)GetUUID {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
Then set the above UUID to my NSString:
NSString *UUID = [nameofclasswhereGetUUIDclassmethodresides UUID];
I then stored that UUID to the Keychain using SSKeyChain
To set the UUID with SSKeyChain:
[SSKeychain setPassword:UUID forService:#"com.yourapp.yourcompany" account:#"user"];
To Retrieve it:
NSString *retrieveuuid = [SSKeychain passwordForService:#"com.yourapp.yourcompany" account:#"user"];
When you set the UUID to the Keychain, it will persist even if the user completely uninstalls the App and then installs it again.
To make sure ALL devices have the same UUID in the Keychain.
Setup your app to use iCloud.
Save the UUID that is in the Keychain to NSUserDefaults as well.
Pass the UUID in NSUserDefaults to the Cloud with Key-Value Data Store.
On App first run, Check if the Cloud Data is available and set the UUID in the Keychain on the New Device.
You now have a Unique Identifier that is persistent and shared/synced with all devices.
Firstly, the UDID is only deprecated in iOS 5. That doesn't mean it's gone (yet).
Secondly, you should ask yourself if you really need such a thing. What if the user gets a new device and installs your app on that? Same user, but the UDID has changed. Meanwhile, the original user might have sold his old device so now a completely new user installs your app and you think it's a different person based on the UDID.
If you don't need the UDID, use CFUUIDCreate() to create a unique ID and save it to the user defaults on the first launch (use CFUUIDCreateString() to convert the UUID to a string first). It will survive backups and restores and even come along with the original user when they switch to a new device. It's in many ways a better option that the UDID.
If you really need a unique device identifier (it doesn't sound like you do), go for the MAC address as pointed out in Suhail's answer.
I was updating my application that was working based only on Unique Identifier which supported iOS 4.3 and above. So,
1) I was unable to use [UIDevice currentDevice].uniqueIdentifier; as it was no longer available
2) I could not use [UIDevice currentDevice].identifierForVendor.UUIDString because it was Available in iOS 6.0 and later only and was unable to use for lower iOS versions.
3) The mac address was not an option as it wasn't allowed in iOS-7
4) OpenUDID was deprecated some time ago and also had issues with iOS-6.
5) Advertisement identifiers were also not available for iOS-5 and below
Finally this was what i did
a) Added SFHFKeychainUtils to the project
b) Generated CFUUID key String
CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));
c) Saved it to Key Chain Utils or else it will generate a new Unique Each Time
Final Code
+ (NSString *)GetDeviceID {
NSString *udidString;
udidString = [self objectForKey:#"deviceID"];
if(!udidString)
{
CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));
CFRelease(cfuuid);
[self setObject:udidString forKey:#"deviceID"];
}
return udidString;
}
+(void) setObject:(NSString*) object forKey:(NSString*) key
{
NSString *objectString = object;
NSError *error = nil;
[SFHFKeychainUtils storeUsername:key
andPassword:objectString
forServiceName:#"LIB"
updateExisting:YES
error:&error];
if(error)
NSLog(#"%#", [error localizedDescription]);
}
+(NSString*) objectForKey:(NSString*) key
{
NSError *error = nil;
NSString *object = [SFHFKeychainUtils getPasswordForUsername:key
andServiceName:#"LIB"
error:&error];
if(error)
NSLog(#"%#", [error localizedDescription]);
return object;
}
For further Details
Some people want to know more about the different options available, and if you do, take a look at the answer from #NSQuamber.java. If you want to know how to use the NSUUID and sync with iCloud, keep reading. This post ended up being more long-winded than I originally wanted, but I hope that it makes it clear for anyone taking these steps!
Using NSUUID
I use the NSUUID class to create the UUID:
NSUUID *uuid = [NSUUID UUID];
Then to create the string, you only need to call the UUIDString method:
NSString *uuidString = [uuid UUIDString];
or do it in one line:
NSString *uuidString = [[NSUUID UUID] UUIDString];
IMHO, this is much easier than trying to use CFUUIDCreate and have a method you have to maintain.
EDIT: I now use UICKeyChainStore
To set the UUID with UICKeyChainStore:
UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:#"com.sample.MyApp"];
keychain[#"com.sample.MyApp.user"] = userID;
To retrieve it:
UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:#"com.sample.MyApp"];
NSString *userID = keychain[#"com.sample.MyApp.user"];
I then stored that UUID to the Keychain using SSKeyChain
To set the UUID with SSKeyChain:
[SSKeychain setPassword:userID forService:#"com.sample.MyApp.user" account:#"com.sample.MyApp"];
To retrieve it:
NSString *userID = [SSKeychain passwordForService:#"com.sample.MyApp.user" account:#"com.sample.MyApp"];
When you set the UUID to the Keychain, it will persist even if the user completely uninstalls the App and then installs it again.
Syncing with iCloud
So it's useful to make sure that all the user's devices use the same UUID. This is to ensure that data is synchronized across all the devices, rather than each device thinking it is a unique user.
There were several questions in the comments for my answer on how synchronization would work, so now that I've got it all working, I'll provide more details.
Configuring iCloud/NSUbiquitousKeyValueStore Use
Click on your project at the top of the Project Navigator in Xcode.
Select Capabilities.
Turn on iCloud.
It should now look something like this:
Using NSUbiquitousKeyValueStore
Using iCloud is fairly simple. To write:
// create the UUID
NSUUID *userUUID = [[NSUUID UUID];
// convert to string
NSString *userID = [userUUID UUIDString];
// create the key to store the ID
NSString *userKey = #"com.sample.MyApp.user";
// Save to iCloud
[[NSUbiquitousKeyValueStore defaultStore] setString:userID forKey:userKey];
To read:
// create the key to store the ID
NSString *userKey = #"com.sample.MyApp.user";
// read from iCloud
NSString *userID = [[NSUbiquitousKeyValueStore defaultStore] stringForKey:userKey];
Before you can write the NSUbiquitousKeyValueStore documentation states that you are required to read from iCloud first. To force a read, call the following method:
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
To have your app receive notifications of changes in iCloud, add the following notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(iCloudStoreDidChange:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object:[NSUbiquitousKeyValueStore defaultStore]];
Creating the UUID with iCloud
Combining NSUUID, SSKeychain and NSUbiquityKeyValueStore, here's my method for generating a user ID:
- (NSUUID *)createUserID {
NSString *userKey = #"com.sample.MyApp.user";
NSString *KEYCHAIN_ACCOUNT_IDENTIFIER = #"com.sample.MyApp";
NSString *userID = [SSKeychain passwordForService:userKey account:KEYCHAIN_ACCOUNT_IDENTIFIER];
if (userID) {
return [[NSUUID UUID] initWithUUIDString:userID];
}
// check iCloud
userID = [[NSUbiquitousKeyValueStore defaultStore] stringForKey:userKey];
if (!userID) {
// none in iCloud, create one
NSUUID *newUUID = [NSUUID UUID];
userID = [newUUID UUIDString];
// save to iCloud
[[NSUbiquitousKeyValueStore defaultStore] setString:userID forKey:userKey];
}
// store the user ID locally
[SSKeychain setPassword:userID forService:userKey account:KEYCHAIN_ACCOUNT_IDENTIFIER];
return [[NSUUID UUID] initWithUUIDString:userID];
}
How to ensure that your User ID is in sync
Because writing to iCloud requires a download of any data in iCloud first, I put the synchronize call at the top of the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method. I also added the notification registration there as well. That allows me to detect any changes from iCloud and handle them appropriately.
Here's a sample:
NSString *const USER_KEY = #"com.sample.MyApp.user";
NSString *const KEYCHAIN_ACCOUNT_IDENTIFIER = #"com.sample.MyApp";
- (void)iCloudStoreDidChange:(NSNotification *)notification {
NSDictionary *userInfo = notification.userInfo;
NSNumber *changeReason = userInfo[NSUbiquitousKeyValueStoreChangeReasonKey];
NSArray *keysChanged = userInfo[NSUbiquitousKeyValueStoreChangedKeysKey];
if (changeReason) {
switch ([changeReason intValue]) {
default:
case NSUbiquitousKeyValueStoreServerChange:
case NSUbiquitousKeyValueStoreInitialSyncChange:
// check changed keys
for (NSString *keyChanged in keysChanged) {
NSString *iCloudID = [[NSUbiquitousKeyValueStore defaultStore] stringForKey:keyChanged];
if (![keyChanged isEqualToString:USER_KEY]) {
NSLog(#"Unknown key changed [%#:%#]", keyChanged, iCloudID);
continue;
}
// get the local key
NSString *localID = [SSKeychain passwordForService:keyChanged account:KEYCHAIN_ACCOUNT_IDENTIFIER];
if (!iCloudID) {
// no value from iCloud
continue;
}
// local ID not created yet
if (!localID) {
// save the iCloud value locally
[SSKeychain setPassword:iCloudID forService:keyChanged account:KEYCHAIN_ACCOUNT_IDENTIFIER];
continue; // continue because there is no user information on the server, so no migration
}
if ([iCloudID isEqualToString:localID]) {
// IDs match, so continue
continue;
}
[self handleMigration:keyChanged from:localID to:iCloudID];
}
break;
case NSUbiquitousKeyValueStoreAccountChange:
// need to delete all data and download new data from server
break;
}
}
}
When the application is launched or when it comes back to the foreground, I force a synchronization with iCloud and verify the integrity of the UUIDs.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self configureSecKeyWrapper];
// synchronize data from iCloud first. If the User ID already exists, then we can initialize with it
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
[self checkUseriCloudSync];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// synchronize changes from iCloud
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
[self checkUseriCloudSync];
}
- (BOOL)checkUseriCloudSync {
NSString *userKey = #"com.sample.MyApp.user";
NSString *KEYCHAIN_ACCOUNT_IDENTIFIER = #"com.sample.MyApp";
NSString *localID = [SSKeychain passwordForService:userKey account:KEYCHAIN_ACCOUNT_IDENTIFIER];
NSString *iCloudID = [[NSUbiquitousKeyValueStore defaultStore] stringForKey:userKey];
if (!iCloudID) {
// iCloud does not have the key saved, so we write the key to iCloud
[[NSUbiquitousKeyValueStore defaultStore] setString:localID forKey:userKey];
return YES;
}
if (!localID || [iCloudID isEqualToString:localID]) {
return YES;
}
// both IDs exist, so we keep the one from iCloud since the functionality requires synchronization
// before setting, so that means that it was the earliest one
[self handleMigration:userKey from:localID to:iCloudID];
return NO;
}
If which UUID came first matters
In my use case of my UserID, I assumed that the value in iCloud is the one to keep, since it would be the first UUID pushed to iCloud, regardless of which device generated the UUID first. Most of you would probably take the same path, since you won't really care which UUID it resolves to, as long as it resolves to a single one. For those of you who actually care about which came first, I suggest you store both the UUID and the timestamp generation ([[NSDate date] timeIntervalSince1970]) so that you can check to see which one is older:
// using dates
NSDate *uuid1Timestamp = [NSDate dateWithTimeIntervalSince1970:timestamp1];
NSDate *uuid2Timestamp = [NSDate dateWithTimeIntervalSince1970:timestamp2];
NSTimeInterval timeDifference = [uuid1 timeIntervalSinceDate:uuid2Timestamp];
// or just subtract
double timeDifference = timestamp1 - timestamp2;
There is a nice alternative on Github which generates a Unique Identifier based on a combination of Mac Address and the Bundle Identifier which works pretty well: UIDevice-with-UniqueIdentifier-for-iOS-5
In iOS7 Apple has introduced a read only property called "identifierForVendor" in the UIDevice class. If you decide to use it you should make note of the following,
This value could be nil if it is accessed before the user unlocks the device
The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them.
The value can also change when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution.
If you need an identifier for advertising purposes, use the advertisingIdentifier property of ASIdentifierManager. However make note that point one discussed above is still true for this as well.
Source: https://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/identifierForVendor
This is a hot topic indeed. I have an app that I have to migrate because it used the UDID to name an XML file to be stored on a server. Then the device with the app would connect to the server and download its specific udid.xml and parse it to work.
Ive been thinking that indeed if the user moves to a new device, the app will break. So I really should use something else. The thing is, I don't use a database for the data. The data is simply stored in an xml format, one xml file per device stored on the cloud.
Im thinking the best thing would be to have the user fill out the data on the web, have php create a token on the fly which will not be stored in a database but rather sent to the user. The user can then input the token on the target device and retrieve the xml in question.
That would be my solution to the problem. Not sure how to implement the whole 'creating unique tokens' thing though.

Reachability Help - WiFi Detection

I have imported Reachability into my application, and I have a couple of how-to questions for you all. Let me explain my application and other tools first.
This application communicates with two things AT THE SAME TIME, an ad-hoc network, and the internet through 3G. Note: The ad-hoc network IS NOT connected to the internet. This works perfectly - it's already implemented and tests out wonderfully.
With that being said, I want to implement Reachability to detect a two things.
1) Is the user connected to a wifi ad-hoc network? (Even better, if possible, is to detect if it is connected to the wifi ad-hoc network with a prefix of WXYZ. For example, if there are two networks listed, one called Linksys and the other called WXYZ-Testing_Platform, it knows whether or not it is connected to WXYZ).
2) Can the user connect to the internet through 3G (or 2G, etc) and access our server?
Thanks in advance
EDIT TO INCLUDE ANSWER FOR FUTURE LOOKERS:
For 1), my code looks like this:
.h
#import <SystemConfiguration/CaptiveNetwork.h> //for checking wifi network prefix
.m
- (BOOL) connectedToWifi
{
CFArrayRef myArray = CNCopySupportedInterfaces();
// Get the dictionary containing the captive network infomation
CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
NSLog(#"Information of the network we're connected to: %#", captiveNtwrkDict);
NSDictionary *dict = (__bridge NSDictionary*) captiveNtwrkDict;
NSString* ssid = [dict objectForKey:#"SSID"];
if ([ssid rangeOfString:#"WXYZ"].location == NSNotFound || ssid == NULL)
{
return false;
}
else
{
return true;
}
}
And for 2), I imported Reachability and have it using this method whenever I go to connect to the server... NOTE:replace http://www.google.com with the server information
-(void) checkIfCanReachServer
{
UIAlertView *errorView;
Reachability *r = [Reachability reachabilityWithHostName:#"http://www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if(internetStatus == NotReachable) {
errorView = [[UIAlertView alloc]
initWithTitle: #"Network Error"
message: #"Cannot connect to the server."
delegate: self
cancelButtonTitle: #"OK" otherButtonTitles: nil];
[errorView show];
}
}
Reachability only lets you know if the device can send data packets out successfully. So
for 1) you should refer to iPhone get SSID without private library. For 2) you will use Reachability only to check for an internet connection then you would need to use NSURLConnection or other network library to make sure you can reach your server.

Find UUID of connected Iphone devices from the objective-c on the mac

Can I find UUID of connected Iphone devices from the objective-c on the mac? Something of a list of connected Iphones trough the usb cable.
Use the ioreg command, and grep the received results. A minimalist implementation:
- (NSString*)getConnectedIphoneUIID
{
NSTask *ioRegTask = [[NSTask alloc] init];
[ioRegTask setLaunchPath:#"/usr/sbin/ioreg"];
[ioRegTask setArguments:[NSArray arrayWithObjects:#"-Src",#"IOUSBDevice",nil]];
NSTask *grepTask = [[NSTask alloc] init];
[grepTask setLaunchPath:#"/usr/bin/grep"];
[grepTask setArguments:[NSArray arrayWithObjects:#"-i", #"usb serial number", nil]];
NSPipe *ioregToGrepPipe = [[NSPipe alloc] init];
[ioRegTask setStandardOutput:ioregToGrepPipe];
[grepTask setStandardInput:ioregToGrepPipe];
NSPipe *outputPipe = [[NSPipe alloc] init];
[grepTask setStandardOutput:outputPipe];
NSFileHandle *outputFileHandle = [[outputPipe fileHandleForReading] retain];
[ioRegTask launch];
[grepTask launch];
NSData *outputData = [[outputFileHandle readDataToEndOfFile] retain];
[ioRegTask release];
[grepTask release];
[outputData release];
NSString *nvcap = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
return nvcap;
}
I could incorporate more checks and further parse the results, to make sure it's really an iPhone, just in case there are more devices listed in there that have the "usb serial number" property set. Checking the "SupportsIPhoneOS" property would further confirm the device's identity. This way, I could actually build a list of connected iPhone/iPod devices, and get their UUID's from the "usb serial number" property.
Apple keeps the iPhone pretty locked down. I don't think you'd find it easy to query anything from the iPhone without some low level code over USB.
IS there a specific reason you need to do this? Can you not just look in the Organizer window in Xcode and see what devices are connected there? The Organizer shows the UUIDs and more information about connected devices, including crash longs, the iPhone's console, screenshots and provisioning.
Try this:
[[UIDevice device] uniqueIdentifier]
for each of your connected devices.