RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-359323

Пётр Иванов's questions

Martin Hope
Пётр Иванов
Asked: 2021-12-03 20:16:34 +0000 UTC

离开后台后 locationManager.stopUpdateLocations 不起作用

  • 1

我在后台使用地理定位跟踪,在应用程序处于后台几分钟后,locationManager.stopUpdateLocations() 调用停止工作 - 顶部的蓝条没​​有被删除,应用程序继续使用地理定位服务(即使启动地理定位后,您只需将应用程序最小化一次)。如果您调用 locationManager.stopUpdateLocations() 时没有将应用程序最小化到后台(或者如果您将应用程序最小化了很短的时间 1-2 分钟),那么服务将关闭并且顶部的蓝条消失。谁面临这个,帮助,我已经花了几天时间 - 都无济于事。禁用所有逻辑,唯一剩下的就是:启动地理定位服务(locationManager.startUpdateLocations)并尝试停止(locationManager.stopUpdateLocations)。

这是带有地理位置的类代码:

import CoreLocation

final class MyLocationService: NSObject, CLLocationManagerDelegate {

    private let locationManager = CLLocationManager()
    

    func sendCoord() {
        print("Send you coordinates")
    }
    
    func requestPermission() {
        locationManager.requestWhenInUseAuthorization()
    }
    
    func start() {
        locationManager.delegate = self
        locationManager.pausesLocationUpdatesAutomatically = false
        locationManager.allowsBackgroundLocationUpdates = true
        locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
        locationManager.distanceFilter = 300
        locationManager.startUpdatingLocation()
        
        sendCoord()
        
    }
    
    func stop() {

        locationManager.pausesLocationUpdatesAutomatically = true
        locationManager.stopUpdatingLocation()
        locationManager.allowsBackgroundLocationUpdates = false
        locationManager.delegate = nil 
    }
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    
        sendCoord()
    }
}

这是 ViewController 类代码:

import UIKit
import Foundation
import CoreLocation

class ViewController: UIViewController {
        
    // *** Internal variables *** //
    private let locationService = MyLocationService()
    var needPermissionForLocationServices = false

    @IBOutlet weak var toolBar: UIToolbar!
    
    @IBOutlet weak var startLocationToolBarButton: UIBarButtonItem!
    
    @IBAction func startLocationToolBarButtonAction(_ sender: UIBarButtonItem) {
        
    if CLLocationManager.locationServicesEnabled() {

            switch(CLLocationManager.authorizationStatus()) {

                case .notDetermined, .restricted, .denied:
           
                    DispatchQueue.main.async(execute: {

                        let alert = UIAlertController(title: "Error!", message: "Location services is off", preferredStyle: UIAlertController.Style.alert)
                alert.addAction(UIAlertAction(title: "Go to settings?", style: UIAlertAction.Style.default, handler: { (alert: UIAlertAction!) in
                print("")
                            UIApplication.shared.open(NSURL(string:UIApplication.openSettingsURLString)! as URL)
                        }))
                        self.present(alert, animated: true, completion: nil)
                    })
                    
                case .authorizedAlways, .authorizedWhenInUse:

                    locationService.start()
                  
                    DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
                        self.tableView.reloadData()
                    }
                    if action.lRefresh {
                        refreshAfterAction(action: action)
                    }
                }
            } else {
                DispatchQueue.main.async(execute: {
                   let alert = UIAlertController(title: "Error!", message: "Location services is off", preferredStyle: UIAlertController.Style.alert)
                alert.addAction(UIAlertAction(title: "Go to settings?", style: UIAlertAction.Style.default, handler: { (alert: UIAlertAction!) in
                print("")
                    UIApplication.shared.open(NSURL(string:UIApplication.openSettingsURLString)! as URL)
                    }))
                    self.present(alert, animated: true, completion: nil)
                })
                locationService.requestPermission()
            }
         
    }

    @IBOutlet weak var stopLocationToolBarButton: UIBarButtonItem!
    
    @IBAction func stopLocationToolBarButtonAction(_ sender: UIBarButtonItem) {
        
        locationService.stop()
         
    }
    
    // *** View Controller Functions *** //
    
    deinit {
        print("Deinit: VC NO MEMORY LEAKS")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        locationService.requestPermission()
        
    }
    
    override func viewDidDisappear(_ animated: Bool) {

    }
    
    override func viewWillAppear(_ animated: Bool) {
       
        view.backgroundColor = UIColor.white
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    
    }
}
ios
  • 1 个回答
  • 10 Views
Martin Hope
Пётр Иванов
Asked: 2020-04-01 01:35:44 +0000 UTC

在密码中授权 type basic 时,符号#swift 4 被错误传输到服务器

  • 0

这是基本的标头代码:

let userName = "userName"
let userPassword = "{"pass":password}"
loginString = String(format: "%@:%@", userName, userPassword)
let loginData = loginString.data(using: String.Encoding.utf8)!
let base64LoginData = loginData.base64EncodedString()
let url = URL(string: "https://mysight.ru/authorize")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Basic \(base64LoginData)", forHTTPHeaderField: "Authorization")
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration)
let task = session.dataTask(with: request as URLRequest) { (data, response, error) in
            self.data = data
            self.response = response as? HTTPURLResponse
            self.error = error

            if (response as? HTTPURLResponse) != nil {
                let myHttpResponse = response as! HTTPURLResponse
                let statusCode = myHttpResponse.statusCode
                switch (statusCode) {
                    case 200:
                        print("Get UserTokens Processing StatusCode=200")
                    case 401:
                        print("User Unauthorized")
                    case 500:
                        print("Get UserTokens Processing StatusCode=500")

                    default:
                        print("Get UserTokens Processing StatusCode=Unknown")
                }
            }
            self.isFinished = true
        }
        task.resume()
    }

如果密码仅包含字母和数字 - 一切正常,状态 200,如果密码中的 # 符号 - 立即出现错误:状态 401:用户未授权

我知道问题出在#字符的传输中,但我不明白如何解决这个问题。如果有人遇到,请帮助。

ios
  • 1 个回答
  • 10 Views
Martin Hope
Пётр Иванов
Asked: 2020-11-15 14:58:58 +0000 UTC

将项目(swift 4.2)发布到AppStore时,链接libPrinterSDK.a库时出错

  • 1

再会。Swift 项目使用迷你热敏打印机 POS-5805DD blueTouth 打印机 SDK。库(打印机自带)libPrinterSDK.a和头文件PrinterSDK.h已添加到项目根目录,头文件通过网桥连接,在真机上启动项目时一切正常,不会发生错误。但是在尝试构建项目上传到AppStore时,最后在链接libPrinterSDK.a库时,出现错误:

ld:无法生成位码包,因为“/Users/ivan/Documents/MyProject/PrinterSDK/libPrinterSDK.a(GCDAsyncSocket.o)”是在没有完整位码的情况下构建的。位码的所有目标文件和库必须从 Xcode 存档或安装构建文件“/Users/ivan/Documents/MyProject/PrinterSDK/libPrinterSDK.a”用于架构 armv7

clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

如果有人有任何使用 libPrinterSDK.a 和 PrinterSDK.h 构建项目的经验,我们将不胜感激。谢谢你。

ios
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5