in-app

2011-06-23 15 views
4

UIボタンを押して画面のスクリーンショットを撮ってすぐにポップアップしてメールを表示できるようにするには、どのコードを使用する必要があるかを知りたい作成し、スクリーンショットを写真ライブラリに保存せずにメールで送信しますか?in-app

多くの感謝!

答えて

12

プロジェクトには、QuartzCoreMessageUIの2つのフレームワークを追加し、次に#import <QuartzCore/QuartzCore.h>#import <MessageUI/MessageUI.h>を追加する必要があります。

あなたのボタンを押してコードを

- (void)buttonPress:(id)sender 
{ 
    UIGraphicsBeginImageContext(self.view.frame.size); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    NSData * imageData = UIImageJPEGRepresentation(image, 1.0); 

    if ([MFMailComposeViewController canSendMail]) { 
     MFMailComposeViewController * mailComposer = [[[MFMailComposeViewController alloc] init] autorelease]; 
     mailComposer.delegate = self; 
     [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"]; 

     /* Configure other settings */ 

     [self presentModalViewController:mailComposer animated:YES]; 
    } 
} 
+0

こんにちはディーパック、のようにする必要があり、私は不明何かを持っています。 xcodeは保存していないので、添付したいスクリーンショットのパスと名前がどこにあるのかを知ることができますか? – Clarence

+0

私はここでいくつかの仮定をしました。あなたのアプリの現在の画面のスクリーンショットを撮りたいと思っていました。だから私は '[self.view.layer renderInContext:..];'ここで 'self'はあなたのView Controllerです。ビューに画像を描画し、画像に 'UIImageJPEGRepresentation'を使って' NSData'オブジェクトを抽出し、JPEG表現を取得しました。次に、 'NSData'オブジェクトをメソッド' addAttachmentData:mimeType:fileName: 'に渡すことができました。ここで' fileName'はメールの受信者が見るものです。 –

+0

これを行うには、ファイルシステムから読み込む必要はありません。別の要件がある場合は、私に知らせてください。 –