在iphone中发送sms inapps时如何检查设备是否为ipod。 我想在设备是ipod touch时发送短信 这是我的代码
smsComposer = [[MFMessageComposeViewController alloc] init];
smsComposer.navigationController.navigationBarHidden = NO;
smsComposer.wantsFullScreenLayout = YES;
if([MFMessageComposeViewController canSendText])
{
smsComposer.body = [NSString stringWithFormat:@"Join me : %@",urlStr];
smsComposer.recipients = numberArr;
smsComposer.messageComposeDelegate = self;
[self.view.superview addSubview:smsComposer animated:NO];
}
这对iPhone来说很好
对于ipod短信发送设施不可用。
我想知道如果设备是ipod。是antbody hav idea abt chking设备类型。
感谢
答案 0 :(得分:1)
use this one:
for detecting device
NSLog(@"name:%@\n model:%@ \n localizedModel:%@ \n systemName:%@ \n systemVersion:%@ \n uniqueIdentifier:%@",[[UIDevice currentDevice] name],
[[UIDevice currentDevice] model],
[[UIDevice currentDevice] localizedModel],
[[UIDevice currentDevice] systemName],
[[UIDevice currentDevice] systemVersion],
[[UIDevice currentDevice] uniqueIdentifier]);
答案 1 :(得分:0)
您应该检查设备是否可以发送短信,而不是设备是否为iPod。
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
BOOL canSendSMS = false;
if (messageClass != nil)
{
if ([messageClass canSendText])
{
canSendSMS = true;
[self displaySMSComposerSheet];
}
}
if(!canSendSMS)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device not configured to send SMS."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
NSLog(@"Device not configured to send SMS.");
}
仅供参考,我如何显示短信撰写表:
- (void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.recipients = [[NSArray alloc] initWithArray:tickedArray];
picker.body = @"Put the default message in here...";
[self presentModalViewController:picker animated:YES];
[picker release];
}
然后在尝试显示视图时触发此方法:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
case MessageComposeResultCancelled:
NSLog(@"Result: SMS sending canceled");
break;
case MessageComposeResultSent:
NSLog(@"Result: SMS sent");
break;
case MessageComposeResultFailed:
NSLog(@"Result: SMS sending failed");
break;
default:
NSLog(@"Result: SMS not sent");
break;
}
[self done:self];
}
同样,我不推荐这个,但是如果你想检查它是什么设备那么你可以使用它:
- (NSString *) platformString
{
NSString *platform = [self platform];
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad";
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad";
if ([platform isEqualToString:@"i386"]) return @"iPhone Simulator";
return platform;
}
答案 2 :(得分:0)
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"]){
//Make ur decision here....
}