triveni
triveni

Reputation: 377

how to check device is ipod when send sms inapps in iphone

how to check device is ipod when send sms inapps in iphone. i want to diasable sending sms when device is ipod touch   here is my code

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


}

this wrking well for iphone For ipod sms sending facility not available . i want to chek if device is ipod .is antbody hav idea abt chking device type . Thanks

Upvotes: 0

Views: 353

Answers (3)

stack2012
stack2012

Reputation: 2186

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

Upvotes: 0

Rahul Juyal
Rahul Juyal

Reputation: 2144

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

Upvotes: 1

ingh.am
ingh.am

Reputation: 26742

You should check if the device can send SMS, not if the device is an 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.");    
}

FYI, how I display the SMS compose sheet:

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

Then this method is fired when trying to display the view:

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

Again, I don't recommend this but if you want to check what device it is then you could use this:

- (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;
}

Upvotes: 0

Related Questions