2

こんにちはMFMessageComposeViewController、iPhone アプリでメッセージを送信するために使用しています。これはiPhoneアプリなので、iPodにも対応しています。また、iPod ではメッセージ機能が利用できないため、メッセージ ボタンをクリックするとアプリがクラッシュします。ユーザーがiPodのメッセージをクリックしてクラッシュしないように、メッセージボタンを非表示にできるように、デバイスがiPodであるかどうかを確認する方法はありますか。

これは、私がメッセージに使用したコードです。

- (IBAction)Message:(id)sender
{
MFMessageComposeViewController *messaging=[[MFMessageComposeViewController alloc]init];
messaging.messageComposeDelegate=self;
[messaging setBody:@"Will of the People""\n""http://bit.ly/1gZhZye"];

[self presentViewController:messaging animated:YES completion:nil];
}


- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:^{UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Done" message:nil delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
    [alert show];
}];
}

そして、これはiPhoneでうまく機能しているようです。ユーザーが iPod を使用しているときにこのボタンを無効にする方法が必要です。

4

6 に答える 6

1

最初に次の方法を使用してデバイスを検出し、デバイスがメッセンジャーをサポートしていない場合はアラートを表示します。

ここにフォームを作成すると、さまざまなデバイスの検出についてより多くのアイデアを得ることができます: iPhone SDK を使用してデバイス (iPhone、iPod Touch) を決定します。

- (IBAction)Message:(id)sender
{
   NSString *deviceType = [UIDevice currentDevice].model;

    if([deviceType isEqualToString:@"iPod Touch 5G"])  {

         // here your alert view to show msg 


    } else {

        if ([MFMessageComposeViewController  canSendText])
        {
          MFMessageComposeViewController *messaging=[[MFMessageComposeViewController alloc]init];
          messaging.messageComposeDelegate=self;
         [messaging setBody:@"Will of the People""\n""http://bit.ly/1gZhZye"];
         [self presentViewController:messaging animated:YES completion:nil];
      }
   }
}
于 2013-12-19T12:21:44.670 に答える
1
    NSString *deviceType = [UIDevice currentDevice].model;
    if ([deviceType hasPrefix:@"iPod"])
    {
        //It's iPod;
        //Disable button
    }
于 2013-12-19T12:03:18.167 に答える
0
 -(IBAction)btnByEmailPressed:(id)sender
 {
     if ([MFMailComposeViewController canSendMail] == NO)
 {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"This device is not able to send mail or Email account is not configured." delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
       [alert show];
       return;
   }
   else
   {

       MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
       controller.mailComposeDelegate = self;
       [controller setTitle:@"Invitation"];
       [controller setSubject:@"My Subject"];
       [controller setMessageBody:@"Your Text" isHTML:YES];
       [self presentViewController:controller animated:YES completion:nil];
   }
}

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
[self becomeFirstResponder];
NSString *strMailResult;
switch (result)
{
    case MFMailComposeResultCancelled:
        strMailResult = NSLocalizedString(@"E-Mail Cancelled",@"");
        break;
    case MFMailComposeResultSaved:
        strMailResult = NSLocalizedString(@"E-Mail Saved",@"");
        break;
    case MFMailComposeResultSent:
        strMailResult = NSLocalizedString(@"E-Mail Sent",@"");
        break;
    case MFMailComposeResultFailed:
        strMailResult = NSLocalizedString(@"E-Mail Failed",@"");
        break;
    default:
        strMailResult = NSLocalizedString(@"E-Mail Not Sent",@"");
        break;
}
   UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"STEP-BY-STEP-STORY",@"") message:strMailResult delegate:self  cancelButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitles:nil];
   [alertView show];
   [self dismissViewControllerAnimated:YES completion:nil];
}
于 2013-12-19T12:59:47.453 に答える