我不知道在这个地方问这个问题是否合适。但是由于我对 iOS 的了解很少,而且我周围没有熟练的 iOS 开发人员...如果有人回答这个问题,我会很高兴..
适用于 iOS 本地通知
是否可以设置用户自定义通知?
就像用户会选择他将收到通知的次数一样 当他想要的时候?
最佳答案
当然这是可能的。您可以通过两种方式执行此操作,这两种方式都假设您将用户设置存储在 NSUserDefaults
中。
方法1;除非您希望触发通知,否则不要启动位置服务。
func prepareForLocationServices {
if (NSUserDefaults.standardUserDefaults().boolForKey("userWantsNotifications")) {
// enable your location services and register for any local notifications you want
}
else {
// maybe enable some ui mentioning the feature, and allowing the user to go to your settings view controller to enable or disable notifications
}
}
方法 2:始终启动位置服务,每当位置更新时,在向用户显示通知之前检查用户设置。
func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if (NSUserDefaults.standardUserDefaults().boolForKey("userWantsNotifications")) {
// send a local notifications
}
else {
// do nothing, since the location update is probably triggered in the background
}
}
如果您询问如何实际创建本地通知,请查看此处的文档; https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/doc/uid/TP40006728-CH3-SW86
关于ios - 是否可以在 iOS 应用程序上设置用户自定义通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37092699/