小编Sjo*_*ors的帖子

iOS 12无缘无故地在后台终止应用程序

从iOS 12开始,CLLocationManager不再在后台运行.应用程序在随机时间没有崩溃日志的情况下终止.这在iOS 12之前运行良好.

为了演示这个问题,我在这里创建了一个示例应用程序

演示应用程序只是启动CLLocationManager并在后台运行它.在后台运行时,我们通过记录它来跟踪它.问题是应用程序被iOS终止.创建演示应用程序以演示此问题.

重现步骤

  1. 在设备上运行应用程序
  2. 很高兴访问位置管理员
  3. 将应用程序放到后台
  4. 等待1-48小时

结果:

  1. 该应用程序已终止

随机时间后应用程序无任何理由终止.

预期结果:

  1. 该应用仍在运行.

它应该如何工作

这是Apple工程师证实的:

一旦CLLocationManager更新在前台启动并且您完成了让它在后台运行的所有工作,位置更新应该在后台运行,直到:

  • 应用程序是强制退出
  • 设备重启
  • 应用停止位置更新
  • app释放CLLocationManager对象
  • 应用程序崩溃
  • 由于内存不足,iOS终止了应用程序
  • locationManager对象被释放,过度释放或被覆盖.您应确保未实例化视图控制器,然后重置locationController类.如果在应用程序处于后台时发生这种情况,您将重新启动更新,这将导致应用程序最终被暂停.您应该确保locationController是一个单例.
  • 应用程序正在崩溃.检查您正在测试的设备上是否有崩溃日志
  • 由于内存不足,iOS正在终止应用程序.在这种情况下,您将在设备上找到显示您的应用程序被终止的JetsamEvent日志.您可以检查时间戳并找到应用程序停止工作时的时间戳.

cllocationmanager ios ios-background-mode ios12

23
推荐指数
1
解决办法
5133
查看次数

iOS9中的CLLocationManager给出错误的位置(iOS8没问题)

从iOS9开始,我们在CCLocationManager上遇到一些奇怪的问题.iOS 7-8没有问题.奇怪的位置会导致应用程序出错.该应用程序在驾驶汽车时使用,我们在TestFlight中有大约50名测试用户,其中一些正在报告这些问题.

应用程序对位置更新做出反应,每个位置更新,每个25米,每个50米都有事可做.为了测试,我将所有这些位置存储在一个数组中.我们的测试用户有一个按钮,可以通过邮件将GPX格式的历史记录发送给我.

例如,发送给我的以下12个地点:

<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="flitsmeister-ios-app-test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
  <wpt lat="51.28165091" lon="5.77329012">
    <datetimegps>2015-09-29T04:36:55.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:55.460</datetimeprocessed>
    <course>61.5</course>
    <speed>13.3</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.1</altitude>
    <sequencenr>0</sequencenr>
  </wpt>
  <wpt lat="51.28138654" lon="5.77244497">
    <datetimegps>2015-09-29T04:36:55.506</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:55.523</datetimeprocessed>
    <course>69.3</course>
    <speed>13.5</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.7</altitude>
    <sequencenr>1</sequencenr>
  </wpt>
  <wpt lat="51.28171319" lon="5.77345935">
    <datetimegps>2015-09-29T04:36:56.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:56.441</datetimeprocessed>
    <course>61.2</course>
    <speed>13.2</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.0</altitude>
    <sequencenr>2</sequencenr>
  </wpt>
  <wpt lat="51.28138654" lon="5.77244497">
    <datetimegps>2015-09-29T04:36:56.562</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:56.571</datetimeprocessed>
    <course>69.3</course>
    <speed>13.5</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.7</altitude>
    <sequencenr>3</sequencenr>
  </wpt>
  <wpt lat="51.28177064" lon="5.77362548">
    <datetimegps>2015-09-29T04:36:57.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:57.440</datetimeprocessed>
    <course>60.1</course>
    <speed>13.4</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>32.9</altitude>
    <sequencenr>4</sequencenr>
  </wpt>
  <wpt lat="51.28138654" lon="5.77244497">
    <datetimegps>2015-09-29T04:36:57.541</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:57.558</datetimeprocessed>
    <course>69.3</course> …
Run Code Online (Sandbox Code Playgroud)

cllocationmanager ios9

20
推荐指数
1
解决办法
1904
查看次数

对Enum的成员'init(from :)'的模糊引用

假设我们有这个枚举:

enum NumberEnumSpecial: Int32 {
    case two = 2, three = 3
}
Run Code Online (Sandbox Code Playgroud)

我想用Int32初始化它,所以我用它:

    let myEnum = NumberEnumSpecial.init(rawValue: 2)
Run Code Online (Sandbox Code Playgroud)

这适用于游乐场项目,但不适用于我的常规App项目.我收到此错误的完全相同的代码:

Ambiguous reference to member 'init(from:)'
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

/Users/sjoerd/GitHub/flitsmeister-ios/app/Flitsmeister7/Model/Melding/DangerZone.swift:91:22: error: ambiguous reference to member 'init(from:)'
        let myEnum = NumberEnumSpecial.init(rawValue: 2)
                     ^~~~~~~~~~~~~~~~~
Swift.RawRepresentable:2:24: note: found this candidate
    public convenience init(from decoder: Decoder) throws
                       ^
Swift.RawRepresentable:2:24: note: found this candidate
    public convenience init(from decoder: Decoder) throws
                       ^
Swift.RawRepresentable:2:24: note: found this candidate
    public convenience init(from decoder: Decoder) throws
                       ^
Swift.RawRepresentable:2:24: note: found this candidate
    public …
Run Code Online (Sandbox Code Playgroud)

enums swift

8
推荐指数
1
解决办法
2209
查看次数

重命名并重写为Swift后,对象解码崩溃

由于我们已经重命名了(Bestemming - > Place)类并将其从Objective-c重写为Swift,因此一些用户会遇到崩溃.我们正在尝试使用NSCoding原则从NSUserDefaults加载对象.

碰撞:

Thread : Crashed: com.apple.main-thread
0  Flitsmeister                   0x10018b720 specialized Place.init(coder : NSCoder) -> Place? (Place.swift)
1  Flitsmeister                   0x10018a6f4 @objc Place.init(coder : NSCoder) -> Place? (Place.swift)
2  Foundation                     0x1839ab92c _decodeObjectBinary + 2276
3  Foundation                     0x1839aaf90 _decodeObject + 304
4  Foundation                     0x1839aa124 +[NSKeyedUnarchiver unarchiveObjectWithData:] + 92
5  Flitsmeister                   0x100103fa0 +[SharedUserDefaultsManager WorkPlace] (SharedUserDefaultsManager.m:72)
6  Flitsmeister                   0x100090830 -[InvoerBestemmingTableViewController viewWillAppear:] (InvoerBestemmingTableViewController.m:106)
7  UIKit                          0x187d8074c -[UIViewController _setViewAppearState:isAnimating:] + 628
8  UIKit                          0x187d804c0 -[UIViewController __viewWillAppear:] + 156
9  UIKit                          0x187e27130 -[UINavigationController _startTransition:fromViewController:toViewController:] + …
Run Code Online (Sandbox Code Playgroud)

nscoding ios

7
推荐指数
1
解决办法
928
查看次数

使用 MKMapCamera 的最佳方式是什么

我找到了三种使用 MKMapCamera 的方法,我想知道哪一种是最值得推荐的。我的目标是跟随用户,我想在每次位置更新时更新相机(所以每秒)。

1.

            MKMapCamera *newCamera = [MKMapCamera camera];
            [newCamera setCenterCoordinate:newCoordinate];
            [newCamera setPitch:60];
            [newCamera setHeading:heading];
            [newCamera setAltitude:eyeAltitude];
            [mapView setCamera:newCamera];
Run Code Online (Sandbox Code Playgroud)

2.

            MKMapCamera *newCamera = [MKMapCamera cameraLookingAtCenterCoordinate:newCoordinate
                                                             fromEyeCoordinate:oldCoordinate
                                                                   eyeAltitude:eyeAltitude];
            [newCamera setPitch:pitch];

            [mapView setCamera:newCamera];
Run Code Online (Sandbox Code Playgroud)

3.

            MKMapCamera *oldCamera = mapView.camera;
            [oldCamera setCenterCoordinate:newCoordinate];
            [oldCamera setPitch:60];
            [oldCamera setHeading:heading];
            [oldCamera setAltitude:eyeAltitude];
Run Code Online (Sandbox Code Playgroud)

Memory wise 似乎 nr 3 是最体面的,还是单例类?在大多数示例中,它们使用 nr1。

对于 nr3,我无法使动画正常工作。

谢谢!

mkmapview ios mkmapcamera

5
推荐指数
1
解决办法
3161
查看次数

为什么我不能比较新阵列的数量?

谁可以给我解释一下这个 ?

if(0 <= -1)
    NSLog(@"Thank god");
if([NSArray new].count <= -1)
    NSLog(@"What the **** ? %i", [NSArray new].count);
if([[NSArray alloc] init].count <= -1)
    NSLog(@"What the **** ? %i", [[NSArray alloc] init].count );
Run Code Online (Sandbox Code Playgroud)

输出是两次What the **** ? 0,我期待没有输出我期望有0作为计数.

如果我将计数放入int或记录它,则输出0(零),但if语句在此处生成true.

if-statement objective-c nsarray ios

3
推荐指数
1
解决办法
155
查看次数

如何在不使用AudioSessionSetProperty的情况下路由到kAudioSessionProperty_OverrideCategoryEnableBluetoothInput

我的iOS6和工作代码将蓝牙设置为输出:

// create and set up the audio session
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
[audioSession setActive: YES error: nil];

// set up for bluetooth microphone input
UInt32 allowBluetoothInput = 1;
OSStatus stat = 0;
stat = AudioSessionSetProperty (
                                         kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
                                         sizeof (allowBluetoothInput),
                                         &allowBluetoothInput
                                         );
Run Code Online (Sandbox Code Playgroud)

从iOS7开始,不推荐使用AudioSessionSetProperty方法.遵循此主题如何在不使用AudioSessionSetProperty的情况下将音频路由到扬声器?您可以将输出更改为AVAudioSessionPortOverrideSpeaker或AVAudioSessionPortOverrideNone但此处没有蓝牙选项.

我的实际目标是支持不使用A2DP但使用HFP的蓝牙设备.

那么如何在不使用弃用方法的情况下实现这一目标呢?

bluetooth avfoundation ios

3
推荐指数
1
解决办法
4806
查看次数