ios - 如何在 Xcode 中从 UIActivityViewController 共享用户位置
<p><p>我知道如何共享其他对象,例如图像、网址、字符串或其他。但我不知道如何从 <code>UIActivityViewController</code> 共享当前位置。
我试过了</p>
<pre><code> @IBAction func sendLocation(sender: UIBarButtonItem) {
if mapView.userLocationVisible {
let currentCoordinate = mapView.userLocation.location!
print(currentCoordinate)
let arrayLocation =
let activityController = UIActivityViewController(activityItems: arrayLocation, applicationActivities: nil)
presentViewController(activityController, animated: true, completion: nil)
} else {
print("User location is not visible")
}
}
</code></pre>
<p>但我在控制台中看到 <strong><+53.09618071,+49.96449468> +/- 20.00m(速度 0.00 mps/路线 -1.00)@ 2015 年 10 月 11 日,萨马拉标准时间下午 1:54:26</强>。 <code>UIActivityViewController</code> 不共享任何位置。请帮帮我。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code> @IBAction func shareLocation(sender: UIBarButtonItem) {
// print(receivedDictionary)
let postalAdress = CNMutablePostalAddress()
postalAdress.street = receivedDictionary["Name"] as! String
postalAdress.city = receivedDictionary["City"] as! String
postalAdress.state = receivedDictionary["State"] as! String
postalAdress.postalCode = receivedDictionary["ZIP"] as! String
postalAdress.country = receivedDictionary["Country"] as! String
postalAdress.ISOCountryCode = receivedDictionary["CountryCode"] as! String
let streetName = receivedDictionary["Name"] as! String
let urlAddress = receivedDictionary["FormattedAddressLines"] as!
// print(urlAddress)
let postalContact = CNLabeledValue(label: streetName, value: postalAdress)
let urlAddressContact = CNLabeledValue(label: "map url", value: "http://maps.apple.com/maps?address=\(urlAddress.description)")
let contact = CNMutableContact()
contact.contactType = .Organization
contact.organizationName = streetName
contact.departmentName = streetName
contact.postalAddresses =
contact.urlAddresses =
// create path
let directory = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
let path = directory.first!.path!.stringByAppendingString("/\(streetName).loc.vcf")
// print(path)
do {
let contactData = try CNContactVCardSerialization.dataWithContacts()
contactData.writeToFile(path, atomically: true)
let url = NSURL(fileURLWithPath: path)
// print(url)
let activityViewController = UIActivityViewController(activityItems: , applicationActivities: nil)
presentViewController(activityViewController, animated: true, completion: nil)
} catch {
print("CNContactVCardSerialization cannot save address")
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在 Xcode 中从 UIActivityViewController 共享用户位置,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33063717/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33063717/
</a>
</p>
页:
[1]