는 방법을 말하는 경우 코코아 장치 터치할 수 있습니다.[중복]
-
05-09-2019 - |
문제
가능한 중복:
iOS-를 검출하는지 여부 지원 장치 전화?
쓰고 있어요 아이폰 응용 프로그램을 제공하는 버튼을 전화 번호로 전화.나는 다음과 같은 코드를 사용하여 다음을 전화 번호를 사용하여 tel:
URL 에서 일반적인 방법:
NSURL* contactTelURL = [NSURL
URLWithString:[NSString
stringWithFormat:@"tel:%@",
contactTel]];
[[UIApplication sharedApplication] openURL:contactTelURL];
그것은 작품에 진짜 아이폰,하지만 나는 그냥'는 지원하지 않는 URL 에'경고에서 시뮬레이터입니다.아마도 그 것이라도 일어날 아이팟 터치지만,나는 테스트하지 않았습니다.그것은 좋은 것을 제거하면 버튼을 사용하여 장치에서 실행되지 않는다.
이 있는지 확인하는 방법을 사용하여 프로그래밍 방식으로부 터치 코코아 장치를 만들 수 있습니다.
해결책
쿼리할 수 있습니다 [[UIDevice currentDevice] model]
, 고 확인하면 그것은 아이폰.
다른 팁
Noah Witherspoon에서 내 iPhone 애플리케이션에서 전화하십시오
시뮬레이터는 전화,지도, YouTube 및 SMS 앱을 포함한 많은 iOS의 URL 체계를 지원하지 않습니다. 이것은 또한 iPod touch 및 iPad와 같은 장치와 전화 기능이없는 iPad의 경우도 마찬가지입니다. -openurl :을 통해 URL 구성표를 사용하기 전에 -Canopenurl :, 현재 장치가 사용중인 URL 구성표를 지원하는지 여부에 따라 예 또는 아니오를 반환합니다.
그래서 쿼리 [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]]
장치가 호출 할 수 있는지 확인합니다.
에서 iPhonedevelopment.blogspot.com
#import <sys/utsname.h>
enum {
MODEL_IPHONE_SIMULATOR,
MODEL_IPOD_TOUCH,
MODEL_IPHONE,
MODEL_IPHONE_3G
};
@interface DeviceDetection : NSObject
+ (uint) detectDevice;
+ (NSString *) returnDeviceName:(BOOL)ignoreSimulator;
@end
@implementation DeviceDetection
+ (uint) detectDevice {
NSString *model= [[UIDevice currentDevice] model];
// Some iPod Touch return "iPod Touch", others just "iPod"
NSString *iPodTouch = @"iPod Touch";
NSString *iPodTouchLowerCase = @"iPod touch";
NSString *iPodTouchShort = @"iPod";
NSString *iPhoneSimulator = @"iPhone Simulator";
uint detected;
if ([model compare:iPhoneSimulator] == NSOrderedSame) {
// iPhone simulator
detected = MODEL_IPHONE_SIMULATOR;
} else if ([model compare:iPodTouch] == NSOrderedSame) {
// iPod Touch
detected = MODEL_IPOD_TOUCH;
} else if ([model compare:iPodTouchLowerCase] == NSOrderedSame) {
// iPod Touch
detected = MODEL_IPOD_TOUCH;
} else if ([model compare:iPodTouchShort] == NSOrderedSame) {
// iPod Touch
detected = MODEL_IPOD_TOUCH;
} else {
// Could be an iPhone V1 or iPhone 3G (model should be "iPhone")
struct utsname u;
// u.machine could be "i386" for the simulator, "iPod1,1" on iPod Touch, "iPhone1,1" on iPhone V1 & "iPhone1,2" on iPhone3G
uname(&u);
if (!strcmp(u.machine, "iPhone1,1")) {
detected = MODEL_IPHONE;
} else {
detected = MODEL_IPHONE_3G;
}
}
return detected;
}
+ (NSString *) returnDeviceName:(BOOL)ignoreSimulator {
NSString *returnValue = @"Unknown";
switch ([DeviceDetection detectDevice]) {
case MODEL_IPHONE_SIMULATOR:
if (ignoreSimulator) {
returnValue = @"iPhone 3G";
} else {
returnValue = @"iPhone Simulator";
}
break;
case MODEL_IPOD_TOUCH:
returnValue = @"iPod Touch";
break;
case MODEL_IPHONE:
returnValue = @"iPhone";
break;
case MODEL_IPHONE_3G:
returnValue = @"iPhone 3G";
break;
default:
break;
}
return returnValue;
}
@end
다음은 장치 모델이 휴대 전화인지 확인하는 데 사용하는 간단한 코드 스 니펫입니다.
if ([[[UIDevice currentDevice] model] rangeOfString:@"Phone"].location != NSNotFound &&
[[[UIDevice currentDevice] model] rangeOfString:@"Simulator"].location == NSNotFound ) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", number] ] ];
}