swift 中拨电话的实现
//MARK: - 弹出视图
func createView() {
var alertView : UIAlertView?
alertView = UIAlertView(title: "110", message: "", delegate: self, cancelButtonTitle: "取消", otherButtonTitles: "呼叫")
alertView?.delegate = self
alertView?.show()
}
//点击响应方法
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
if buttonIndex == 1 {
//调用获取用户地理位置信息
getMapData()
var url1 = NSURL(string: "tel://110")
UIApplication.sharedApplication().openURL(url1!)
} else {
return
}
}
//MARK:_调用获取用户地理位置信息
func getMapData() {
mapLacationManager = AMapLocationManager()
mapLacationManager.allowsBackgroundLocationUpdates = true
mapLacationManager.startUpdatingLocation()
mapLacationManager.requestLocationWithReGeocode(true) { (location, regecode, error) in
print(location)
if (location != nil) {
self.LONGITUDES = location.coordinate.longitude
self.LATITUDES = location.coordinate.latitude
} else {
print(error)
}
if self.LONGITUDES != nil && self.LATITUDES != nil {
self.getUserAddress()
}
}
}
//获取用户所在位置信息ADDRESS
func getUserAddress() {
let latitude : CLLocationDegrees = LATITUDES!
let longitude : CLLocationDegrees = LONGITUDES!
let location : CLLocation = CLLocation.init(latitude: latitude, longitude: longitude)
//反地理编码
self.geocoder.reverseGeocodeLocation(location, completionHandler: { ( placemarks : [CLPlacemark]?, error : NSError?) in
print("placemarks:\(placemarks)")
if (error != nil) {
print("你输入的地址没找到,可能在月球上")
} else {
var placemark : CLPlacemark = (placemarks?.first)!
self.ADDRESS = placemark.name
}
if self.ADDRESS != nil {
self.UploadLocation()
}
})
}
func UploadLocation() {
let model : ShareModel = ShareModel()
if (!model.NetWorking) {
NSHelper.showAlertTitle("网络不可用,请检查网络连接。", forView: self.view)
return
}
let dic : [String : AnyObject] = NSDictionary(dictionaryLiteral: ("USERMOBILE",AppSetting.mobile!),("IDCARD",AppSetting.userIdNum!),("LONGITUDES",LONGITUDES!),("LATITUDES",LATITUDES!),("ADDRESS",ADDRESS!),("CITYCODE",AppSetting.homeCity!)) as! [String
: AnyObject]
let tools = NetWorkTools.sharedNetWorkTools()
let parmeters = ["auth": tools.toAuthJSONString(),"info" : tools.toJSONString(dic)]
let hud : MBProgressHUD = MBProgressHUD.init(view: self.view)
self.view.addSubview(hud)
hud.labelText = "你的位置发送中..."
ZPHttpTool.POST(tools.baseUrl + cfg.insertBJXX(), parameters: parmeters, success: { (person) in
hud.hide(true)
var reqDic : [String : AnyObject] = person as! [String : AnyObject]
if reqDic["errCode"]?.integerValue == 0 {
self.mapLacationManager.stopUpdatingLocation()
print(reqDic["msg"] as! String)
} else {
print(reqDic["msg"] as! String)
}
}) { (error) in
print("error:\(error)")
}
}
更多推荐



所有评论(0)