【问题标题】:Screenshot/Share MapView to Send email-iOS截图/分享 MapView 发送邮件-iOS
【发布时间】:2012-10-19 14:07:17
【问题描述】:

我一直在开发天气应用程序。我想知道如何附加/捕获现有地图以通过电子邮件发送?

任何想法或任何有用的链接。非常感谢提前。

【问题讨论】:

  • 这个问题你解决了吗?
  • 你好 Nada,请看下面我的回答。
  • 查看我的更新答案

标签: ios ios5 ios6 android-mapview


【解决方案1】:

您可以使用 UIGraphicsGetImageFromCurrentContext 进行屏幕截图。然后您可以使用此屏幕截图附加到电子邮件。

- (void)twitterButtonPressed {


    NSString *post=[[NSString alloc]initWithFormat:@"I've burned so far %d Calories today -  update from iPhone app Run Burn Calories!", self.userActivityTotalCount];
    NSURL *url=[NSURL URLWithString:@"www.xxx.uh.edu"];
    UIImage *iconImage2=[self imageWithImage:iconImage scaledToSize:CGSizeMake(73.0, 73.0)];
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        SLComposeViewController *twitterSheet=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
        [twitterSheet setInitialText:post];
        [twitterSheet addURL:url];
        [twitterSheet addImage:iconImage2];
        [self presentViewController:twitterSheet animated:YES completion:nil];
        SLComposeViewControllerCompletionHandler completion=^(SLComposeViewControllerResult result){
            switch (result) {
                case SLComposeViewControllerResultDone:
                    NSLog(@"posted successfully!");
                    break;
                case SLComposeViewControllerResultCancelled:
                    NSLog(@" could not posted!");
                    break;

                default:
                    break;
            }
            [twitterSheet dismissViewControllerAnimated:YES completion:nil];

        };
        twitterSheet.completionHandler=completion;

    }
    else{
        UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Sorry" message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account set up" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }

}

-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage =UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;

}

【讨论】:

    【解决方案2】:

    首先,如果现有地图尚未采用这种格式,我会将其转换为图像。完成此操作后,发送电子邮件非常简单。这是我的应用程序中用于发送电子邮件的 sn-p 代码。

    - (void) emailPhoto {
    
        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;
    
        // Set the subject of email
        [picker setSubject:@"Subject of the Email"];
    
        // Add email addresses
        // Notice three sections: "to" "cc" and "bcc"
        //[picker setToRecipients:[NSArray arrayWithObjects:@"emailaddress1@domainName.com", @"emailaddress2@domainName.com", nil]];
        //[picker setCcRecipients:[NSArray arrayWithObject:@"emailaddress3@domainName.com"]];
        //[picker setBccRecipients:[NSArray arrayWithObject:@"emailaddress4@domainName.com"]];
    
        // Fill out the email body text
        NSString *emailBody = @"Text to appear in the email."; 
    
        // This is an HTML formatted email
        [picker setMessageBody:emailBody isHTML:NO];
    
        // Create NSData object as PNG image data from camera image
        // This is where I take my self.workingImage object and convert to data object
        NSData *data = UIImagePNGRepresentation(self.workingImage);
    
        // Attach image *data* object to the email
        [picker addAttachmentData:data mimeType:@"image/png" fileName:@"Image"];
    
        // Show email view
        [self presentModalViewController:picker animated:YES];
    
        // Now the user can send or cancel the email as they please
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多