如何将NSUUID
转换为NSString
?
NSString *url = [self mysql_process:ESTIMOTE_PROXIMITY_UUID];
- (NSString*)mysql_process:(NSUUID *)beacon_id
{
NSString *strURL = [NSString stringWithFormat:@"http://path_to_php_file/mysql.php?id=%@", beacon_id];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
return strResult;
}
当我尝试NSLog
URL
我得到一个指针时,在这种情况下显示我的NSUUID
,ESTIMOTE_PROXIMITY_UUID
。
答案 0 :(得分:11)
NSUUID
有一个方法:-(NSString*)UUIDString;
。
所以:
NSString *uuidString = [yourNSUUID UUIDString]
答案 1 :(得分:1)
swift 3版
例如:
让uuidStringValue =“12345678-1111-2222-3333-4567891012B4”
让proximityUUID = NSUUID(uuidString:uuidStringValue)
答案 2 :(得分:0)
如果你想要来自NSUUID的NSString。使用NSUUID的UUIDString ...
NSUUID *uuidStringRef = [[UIDevice currentDevice] identifierForVendor];
NSString *stringRef = [uuidStringRef UUIDString];//you can replace uuidStringRef with your ESTIMOTE_PROXIMITY_UUID
希望它可以帮助你......!
答案 3 :(得分:0)
NSString *url = [self mysql_process:ESTIMOTE_PROXIMITY_UUID];
- (NSString*)mysql_process:(NSUUID *)beacon_id {
**NSString *strDeviceUUID = [beacon_id UUIDString];** // Converts NSUUID to UUIDString format
NSLog(@"beacon_id : %@ strDeviceUUID : %@ ", beacon_id,strDeviceUUID);
NSString *strURL = [NSString stringWithFormat:@"http://path_to_php_file/mysql.php?id=%@", strDeviceUUID];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
return strResult;
}
此功能存在于Foundation框架的NSUUID.h文件中。
/* Return a string description of the UUID, such as "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" */
- (NSString *) UUIDString;