我正在尝试使用发送电子邮件选项设置应用.
我有这个代码:
import Foundation
import MessageUI
import UIKit
class emailClass: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}
sendEmail()
}
func sendEmail() {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["address@example.com"])
composeVC.setSubject("Hello!")
composeVC.setMessageBody("Hello this is my message body!", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check …Run Code Online (Sandbox Code Playgroud) 我试图从给定的点找出高度,但我没有用我的iPad得到它.我已经定义了我的高度变量:
var altitude: CLLocationDistance = 0.0
Run Code Online (Sandbox Code Playgroud)
我做了这个功能:
func getAltitude(latitude: CLLocationDistance, longitude: CLLocationDistance) -> CLLocationDistance {
//Get altitude of touched point
locationManager.requestWhenInUseAuthorization()
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.desiredAccuracy = kCLLocationAccuracyBest
let touchPointLocation = CLLocation(latitude: latitude, longitude: longitude)
let altitude = touchPointLocation.altitude
return altitude
}
Run Code Online (Sandbox Code Playgroud)
例如,当我触摸地图时,我试图在长按中获得这样的高度:
let touchPoint = gestureRecognizer.location(in: self.map)
let coord = map.convert(touchPoint, toCoordinateFrom: self.map) //now this coord is working ok. Its touched point coordinates
let altitude = getAltitude(latitude: coord.latitude, longitude: coord.longitude)
print(altitude) //I get 0.0 here :(
Run Code Online (Sandbox Code Playgroud)
为什么这是错的?我怎样才能做到这一点?
我正在尝试向地图添加注释。我内部有坐标的点数组。我正在尝试从这些坐标添加注释。
我有这个定义:
var points: [CLLocationCoordinate2D] = [CLLocationCoordinate2D]()
let annotation = MKPointAnnotation()
Run Code Online (Sandbox Code Playgroud)
点内部具有坐标。我检查了。我这样做:
for index in 0...points.count-1 {
annotation.coordinate = points[index]
annotation.title = "Point \(index+1)"
map.addAnnotation(annotation)
}
Run Code Online (Sandbox Code Playgroud)
它一直仅添加最后一个注释...而不是全部添加。为什么是这样?顺便说一句,有没有办法删除指定的注释,例如按标题?
我正在做一个项目Swift 3- xcode 8,我正在尝试使用核心数据来保存并在数据库表"用户"中显示一些图像.此图片是其个人资料中的用户照片.
现在我已经设法保存字符串并从核心数据中显示它们,但我在处理图像时遇到了问题.
这是我到目前为止:
将USERS添加到核心数据中
func addUser() {
let app = UIApplication.shared.delegate as! AppDelegate
let context = app.persistentContainer.viewContext
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Users")
request.returnsObjectsAsFaults = false
let newUser = NSEntityDescription.insertNewObject(forEntityName: "Users", into: context)
if (firstName.text == "" && lastName.text == "" && contact.text == "" && email.text == "") { //if we have a user profile delete it
deleteUser()
} else { // add a new user profile
newUser.setValue(firstName.text, forKey: "firstName")
newUser.setValue(lastName.text, forKey: "lastName")
newUser.setValue(contact.text, …Run Code Online (Sandbox Code Playgroud)