私はデバイスのMacとIPアドレスを取得します。しかし、デバイス名を取得しないでください。iPhone SDKでデバイス名をプログラムで取得する方法は?
デバイスの「ネットワークユーティリティ」のように、可能な場合はどうすればより多くの情報を得ることができますか?
のiOS 4.1以降で私はデバイスのMacとIPアドレスを取得します。しかし、デバイス名を取得しないでください。iPhone SDKでデバイス名をプログラムで取得する方法は?
デバイスの「ネットワークユーティリティ」のように、可能な場合はどうすればより多くの情報を得ることができますか?
のiOS 4.1以降で、あなたがこれを行うことができます:あなたはSSID名を探しているなら...
- (id)fetchSSIDInfo
{
NSArray *ifs = (id)CNCopySupportedInterfaces();
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
id info = nil;
for (NSString *ifnam in ifs) {
info = (id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam);
NSLog(@"%s: %@ => %@", __func__, ifnam, info);
if (info && [info count]) {
break;
}
[info release];
}
[ifs release];
return [info autorelease];
}
NSLog(@"uniqueIdentifier: %@", [[UIDevice currentDevice] uniqueIdentifier]);
NSLog(@"name: %@", [[UIDevice currentDevice] name]);
NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]);
NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]);
NSLog(@"model: %@", [[UIDevice currentDevice] model]);
NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]);
#import <ifaddrs.h>
#import <arpa/inet.h>
- (NSString *)getIPAddress {
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0) {
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL) {
if(temp_addr->ifa_addr->sa_family == AF_INET) {
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
return address;
}
私はすでにipとmacのデバイス名を取得しないでください。それを取得するには? – Dhaval
こんにちはDhaval、あなたがこのためにどんな解決策を見つけますか? – iBhavik
@ i-bhavikを共有してください。デバイス名を取得できませんでした。デバイス情報を取得します。 – Dhaval
誰もがこれを進歩していますか?私はまた、iNetのように、私のアプリにデバイス名を見つけてもらいたい。私はpingできます、私はARPテーブルを読むことができます、私はマシン名を見つけることができません。どんな助けもありがとう! – Jelle