2011-09-23 40 views
0

如何检查设备是ipod在iPhone发送短信inapps。 我想diasable发送短信时,设备是iPod touch的 这里是我的代码如何检查设备是ipod当发送短信inapps在iphone

 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]; 


} 

这wrking以及为iPhone 为iPod短信发送不可用设施。 我想如果设备是ipod .is antbody hav idea abt chking设备类型。 谢谢

回答

0
NSString *deviceType = [UIDevice currentDevice].model; 
    if([deviceType isEqualToString:@"iPhone"]){ 
     //Make ur decision here.... 
     } 
+0

你可以有一个其他案例或用@“iPod”替换字符串 – booleanBoy

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.");  
} 

仅供参考,我怎样显示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; 
} 
+0

你的代码是好的..但我想检测设备type.if我有那么设备类型就会显示alertview .showing alertview晚part.fist我想清洁香港的设备类型 – triveni

+0

我已经将代码放进去。你真的不应该只检查设备类型,例如iPhone可能没有SIM卡。最后,只需调用'NSString * device = [self platformString];'然后检查什么字符串是。随意修改该方法,如果这使得它更容易... –

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]);