2011-09-23 67 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]);