【问题标题】:trigger localNotification only when user enters a specified region仅当用户进入指定区域时触发 localNotification
【发布时间】:2015-11-03 12:43:59
【问题描述】:

这是我的didEnterRegion 函数代码。问题是通知在进入和退出时触发。仅当用户输入位置时,我该怎么做才能触发通知?

func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) {
        var localNotification:UILocalNotification = UILocalNotification()
        localNotification.alertBody = "you've entered rohini sector -8"
        localNotification.region = region
        UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
        NSLog("Entering region")
    }

【问题讨论】:

  • 为什么要在本地通知中指定区域?自从您接到didEnterRegion 的电话后,您就已经知道他们在该地区,因此在通知上指定地区是多余的
  • @Paulw11thanx 人。不知道我怎么错过了这个。现在可以完美运行。

标签: ios swift notifications uilocalnotification region-monitoring


【解决方案1】:

您没有指定是否要监视进入或退出该区域。创建区域时,您设置 notifyOnExit 或 notifyOnEntry 。如果您只想退出,则将该值设置为真,另一个为假...或者如果只输入..则相反

///// snipped taken from ray wenderlichs code...

// 1
let region = CLCircularRegion(center: geotification.coordinate,
    radius: geotification.radius, identifier: geotification.identifier)

// 2
region.notifyOnEntry = false
region.notifyOnExit = true

【讨论】:

    【解决方案2】:

    您无需在本地通知中指定区域。您已经知道该设备在该区域内,因为您已致电 didEnterRegion - 在通知上指定区域是多余的 - 您可以简单地发布通知而不指定区域。

    【讨论】:

      猜你喜欢
      • 2013-06-09
      • 1970-01-01
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      相关资源
      最近更新 更多