发表日期:2016-08 文章编辑:小灯 浏览次数:1139
王宝强的事,我们就不多继续八卦拉,对于从未接触过编程的人,可以私信我,教大家复制以下代码即可入门,作为程序猿,我们用swift写一个可以监测女朋友一举一动的app来造福广大男同胞吧,让那些马蓉,金莲等等坏女人动机扼杀在app之下吧!
这里先说说实现思路,首先需要学习两个API:
这个不用多说就是要来获取你的(男)女朋友的定位,并通过设置前后台都使用来全天候监测(他)她的位置信息,拿到准确的经纬度,甚至可以调用该定位附近的摄像头来检查(他)她和什么人在一起
这个主要用来监视你的(男)女朋友的心率,根据网上的一些系数来确定对方是否在说谎和是否在做“剧烈运动”
教程主要分两个部分来实现,具体细节可以因人而异进行修改,因为里面涉及搭建一个小型的简单服务器,所以后面我会在教程最后提供一个api给大伙们做测试之用的。通过让另外一半安装我们做的这个app,可以有效地监察对方的一举一动,从而做到防微杜渐,万无一失!
废话不多说,我先介绍一下CoreLocation的用法
iOS8+定位必须请求获取用户的授权,这里一定要写requestAlwaysAuthorization()这样就能随时监测拉
import UIKit import CoreLocationclass ViewController: UIViewController {private lazy var mgr : CLLocationManager = CLLocationManager()override func viewDidLoad() { super.viewDidLoad()// iOS8+定位必须请求获取用户的授权,这里一定要写requestAlwaysAuthorization()这样就能随时监测拉mgr.requestAlwaysAuthorization()// 开始定位 mgr.startUpdatingLocation()// 设置代理 mgr.delegate = self// mgr其他属性的补充 // 1.设置定位的精确度 /*kCLLocationAccuracyBestForNavigation: 导航精确度(最精确)kCLLocationAccuracyBest: 最好精确度(默认)kCLLocationAccuracyNearestTenMeters: 10米的误差kCLLocationAccuracyHundredMeters: 100米的误差kCLLocationAccuracyKilometer: 千米误差kCLLocationAccuracyThreeKilometers: 三千米的误差 */ // 精确度越高, 越耗电 mgr.desiredAccuracy = kCLLocationAccuracyBestForNavigation// 2.设置用于移动多少距离,重新进行定位 mgr.distanceFilter = 100 }}extension ViewController : CLLocationManagerDelegate { func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { print("定位到用户的位置")// 1.校验用户是否有位置 guard let lastLocation = locations.last else{ return }// 2.获取具体的信息 // 2.1.获取用户的经纬度(重要) let coordinate = lastLocation.coordinate print("纬度:\(coordinate.latitude) 经度:\(coordinate.longitude)")} } 这里我写了一个服务器专门监听目标上传的定位
import UIKit import CoreLocationclass ViewController: UIViewController {private lazy var mgr : CLLocationManager = CLLocationManager()override func viewDidLoad() { super.viewDidLoad()// iOS8+定位必须请求获取用户的授权 mgr.requestWhenInUseAuthorization()// 开始定位 mgr.startUpdatingLocation()// 设置代理 mgr.delegate = self }}extension ViewController : CLLocationManagerDelegate { func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { print("定位到(男)女朋友的位置")manager.stopUpdatingLocation()// 1.校验用户是否有位置 guard let lastLocation = locations.last else{ return }// 2.获取具体的信息 let coordinate = lastLocation.coordinate print("纬度:\(coordinate.latitude) 经度:\(coordinate.longitude)")// 3.从服务器请求女朋友位置的经纬度(1 = 111km) let latitude = 23.1351 let longitude = 113.370 let location = CLLocation(latitude: latitude, longitude: longitude)// 4.计算两个人之间经纬度的距离 let distance = lastLocation.distanceFromLocation(location) print(distance) } } 这样第一步就完成了,后面还会不断介绍用swift来完善这个app!
我是子祖,来了就点个赞再走,喜欢就关注我,我还会陆续更新更多项目让大家去练手,或者你有什么语言想了解的都可以和我聊聊!