我的应用程序在iOS12.4中运行正常,但在iOS 11中崩溃

时间:2019-10-28 19:17:38

标签: ios swift core-bluetooth

我的应用程序在iOS 12.4中可以正常运行,但在iOS 11中崩溃。

以下代码在iOS 11中返回nil。

func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)
{
    if characteristic == rxCharacteristic
    {
        if let ASCIIstring = NSString(data: characteristic.value!, encoding: String.Encoding.utf8.rawValue)
        {
            characteristicASCIIValue = ASCIIstring
            print("Value Recieved: \((characteristicASCIIValue as String))")
            NotificationCenter.default.post(name:NSNotification.Name(rawValue: "Notify"), object: nil)

        }
    }
}

1 个答案:

答案 0 :(得分:0)

每次使用强制展开时,您都会在值不符合预期的情况下寻求崩溃,因此请避免发生这种情况:

from django.urls import path
from . import views

app_name = 'songs'

urlpatterns = [
    path('', views.song_list, name="list"),
    path('<slug>/', views.song_detail, name="detail")
]