我有这个Swift代码,当用户靠近某个点时,它会振动手机,并且我有一个带有很多标记(经度和纬度)的.csv文件。 如何从地图中隐藏这些标记,但仍保持振动的功能?
function getData(repolink) {
readDataFromGit('https://api.github.com/repos/' + repolink + '/git/trees/master?recursive=1', function(text){
data = JSON.parse(text);
$.each(data, function(i, v) {
// Retrieve v.login data!
data = v.login;
})
});
}
function readDataFromGit(link, callback) {
var request = new XMLHttpRequest();
request.overrideMimeType("application/json");
request.open('GET', link, true);
request.onreadystatechange = function() {
if (request.readyState === 4 && request.status == "200") {
callback(request.responseText);
}
};
request.send(null);
}
答案 0 :(得分:1)
查看iOS 10中的新用户通知规定。它们可以让您提醒用户您是否处于前台,并且能效更高。如果您没有显示积分,则没有理由让MapKit参与。
要求获得警报的用户权限 - 通常需要查看文档和/或WWDC视频。您可以注册的点数也有限制,这可能是您的问题所在。
作为参考,I' m用于此的代码如下:
[In your AppDelegate to get required user authorization]
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge])
{ (granted, error) in
let regionAction = UNNotificationAction(identifier: "regionAlert", title: "regionAlert", options: [])
let regionCategory = UNNotificationCategory(identifier: "notify-region", actions: [regionAction], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([regionCategory])
}
[In the class where you want to use the alerts]
private func setAlert(_ alertPosition: Position, alertTitle: String, alertSubtitle: String, alertBody: String)
{
unowned let myself = self
let alertCenter = CLLocationCoordinate2DMake(alertPosition.coordinate.latitude, alertPosition.coordinate.longitude)
let alertRegion = CLCircularRegion.init(center: alertCenter, radius: Setting.shared.alertRegionRadius, identifier: alertTitle)
alertRegion.notifyOnEntry = true
alertRegion.notifyOnExit = true
content.title = "Trail*Head Alert"
content.subtitle = alertSubtitle
content.body = alertBody
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "notify-region"
if content.badge != nil {
content.badge = NSNumber(value: Int(content.badge!) + 1)
} else {
content.badge = 1
}
let trigger = UNLocationNotificationTrigger.init(region: alertRegion, repeats: false)
let request = UNNotificationRequest(identifier: alertTitle, content: content, trigger: trigger)
center.add(request) { error in
if (error != nil){
print("Add Notification error: ", error!)
}
}
UNUserNotificationCenter.current().delegate = myself
}
// UNUserNotificationCenterDelegate function called if app is in foreground when an alert is triggered
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { completionHandler( [.alert,.sound]) }
// Function to deregister any active alert regions.
func stopAlerts()
{
if alertStatus {
alertStatus = false
center.removeAllPendingNotificationRequests()
}
}
答案 1 :(得分:0)
func setupData() {
pointsDataSource = PointsDataSource(with: "San Francisco")
//if let pointsDataSource = pointsDataSource {
//map.addAnnotations(pointsDataSource.annotations)
//}
}