你應該檢查設備是否可以發送短信,而不是設備是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.");
}
僅供參考,我怎樣顯示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;
}
你可以有一個其他案例或用@「iPod」替換字符串 – booleanBoy