У меня есть простое приложение, которое берет частичный снимок экрана, а затем посылает SMS-результирующее изображение.Невозможно прикрепить изображение к приложению SMS
Изображение, прикрепленное к SMS во всплывающем диалоговом окне SMS, не является изображением, которое я захватил с помощью скриншота - это «пустое» изображение.
Вот мой код:
@IBAction func smsScreenShot(sender: AnyObject) {
// Declare the snapshot boundaries
let top: CGFloat = 100
let bottom: CGFloat = 60
// The size of the cropped image
let size = CGSize(width: view.frame.size.width, height: view.frame.size.height - top - bottom)
// Start the context
UIGraphicsBeginImageContext(size)
// use context in a couple of places
let context = UIGraphicsGetCurrentContext()!
// Transform the context so that anything drawn into it is displaced "top" pixels up
CGContextTranslateCTM(context, 0, -top)
// Draw the view into the context (this is the snapshot)
view.layer.renderInContext(context)
let snapshot = UIGraphicsGetImageFromCurrentImageContext()
// End the context (this is required to not leak resources)
UIGraphicsEndImageContext()
// Composing the SMS
if !MFMessageComposeViewController.canSendText() {
print("SMS services are not available")
}
if (MFMessageComposeViewController.canSendText()) {
let composeVC = MFMessageComposeViewController()
composeVC.messageComposeDelegate = self
composeVC.recipients = []
composeVC.body = "Have a look at this image!!";
// Attaching the image to the SMS.
let image = snapshot
let imageData = UIImagePNGRepresentation(image)
composeVC.addAttachmentData(imageData!, typeIdentifier: "image/png", filename:"my image")
self.presentViewController(composeVC, animated: true, completion: nil)
}
}
Я исследовал это в течение нескольких часов и не вижу, где я неправильно.
У меня есть идентичный код для добавления вложения в электронное письмо в приложении, с очевидными различиями в контроллерах, и он отлично работает. Просто не работает в отношении сообщений в приложении.
Спасибо!
Awesome! Оно работает! Любая идея, почему 'composeVC.addAttachmentData (imageData !, typeIdentifier:« image/png », filename:« my image »)' работал для моего письма в приложении, а не в приложениях sms? –
Вы указали неверный «UTI (Uniform Type Identifier)», просто проверьте https://developer.apple.com/library/prerelease/ios/documentation/Miscellaneous/Reference/UTIRef/Introduction/Introduction.html#//apple_ref/ doc/uid/TP40009257 – Vizllx
Отлично! Terima Kasih :) –