Process kill() returned unexpected error 1 Xcode 11.2 - iOS 13.2 - Swift 5 - swift5

Text translated by google
I am using a webview and when I upload the data to the webview it shows me these messages. What should I modify, is it a mistake, can it cause problems for my application?
import UIKit
import WebKit
class BeneficiosViewController: UIViewController , WKNavigationDelegate{
// MARK: - Declarando Variables
var webView: WKWebView!
// MARK: - LOAD
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Beneficios"
self.navigationController?.navigationBar.titleTextAttributes=[NSAttributedString.Key.font: UIFont(name: "carnas", size: 22) as Any]
let url = URL(string: "https://www.sites.google.com/pageweb")
webView.load(URLRequest(url: url!))
webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, context: nil)
webView.allowsBackForwardNavigationGestures = true
}
// MARK: - Funcion para cargar una web
override func loadView(){
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "......."{
print(Float(webView.estimatedProgress))
}
}
}
Log Detail:
2019-11-22 09:02:25.003545-0500 ScharffDev[6600:1264134] [Process] kill() returned unexpected error 1
2019-11-22 09:02:25.003696-0500 ScharffDev[6600:1264134] [Process] kill() returned unexpected error 1
2019-11-22 09:02:25.004011-0500 ScharffDev[6600:1264134] [Process] kill() returned unexpected error 1
2019-11-22 09:02:25.004173-0500 ScharffDev[6600:1264134] [Process] kill() returned unexpected error 1
2019-11-22 09:02:25.004466-0500 ScharffDev[6600:1264134] [Process] kill() returned unexpected error 1
2019-11-22 09:02:25.004614-0500 ScharffDev[6600:1264134] [Process] kill() returned unexpected error 1
2019-11-22 09:02:25.004820-0500 ScharffDev[6600:1264134] [Process] kill() returned unexpected error 1
2019-11-22 09:02:25.004965-0500 ScharffDev[6600:1264134] [Process] kill() returned unexpected error 1

Apple has finally fixed this bug. Updating to iOS 13.4 makes the error message disappear.
It was just a bug with the OS (versions 13.2 and 13.3), nothing that could cause the app to crash.

Related

Detect URL Change in ContentView.swift iOS app Swift

Trying to detect change event of the URL being navigated to somewhere else when the user changes the currently viewed webpage. Here is my code.
struct WebView: UIViewRepresentable {
var view = WKWebView()
init() {
print("initialized")
}
func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let newValue = change?[.newKey] as? Int, let oldValue = change?[.oldKey] as? Int, newValue != oldValue {
//Value Changed
print(change?[.newKey])
}else{
//Value not Changed
print(change?[.oldKey])
}
}
func makeUIView(context: UIViewRepresentableContext<WebView>) -> WKWebView {
while(!authenticated) {
}
DispatchQueue.main.async {
var url = URL(string:"https://www.runixcoin.com/")!
if (faceIdSuccess) {
url = URL(string:"https://www.runixcoin.com/dashboard/auth-login-basic.php?face_id=true")!
}
else {
url = URL(string:"https://www.runixcoin.com/dashboard/auth-login-basic.php?return_url=https://www.runixcoin.com/dashboard/dashboard-4.php")!
}
let request = URLRequest(url: url)
view.load(request)
view.addObserver(view, forKeyPath: "URL", options: .new, context: nil)
}
return view
}
func updateUIView(_ uiView: WKWebView, context: UIViewRepresentableContext<WebView>) {
}
typealias UIViewType = WKWebView
}
The observeValue function is getting called and printing the results I want when the user navigates away from the current page, however the app is crashing... I want to stop the app from crashing. I even tried using the removeObserver code and it either prevented the function from being called or would still crash... What do I need to do?
2022-04-04 18:21:55.489370-0400 Runixcoin[6797:1762100] [error] warning: View context accessed for persistent container runixcoin with no stores loaded
CoreData: warning: View context accessed for persistent container runixcoin with no stores loaded
initialized
Logged in with FaceID
2022-04-04 18:21:58.914721-0400 Runixcoin[6797:1762100] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<WKWebView: 0x106025e00; frame = (0 0; 428 796); layer = <CALayer: 0x283bb1b80>>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: URL
Observed object: <WKWebView: 0x106025e00; frame = (0 0; 428 796); layer = <CALayer: 0x283bb1b80>>
Change: {
kind = 1;
new = "https://www.runixcoin.com/dashboard/auth-password-basic.php";
}
Context: 0x0'
*** First throw call stack:
(0x1811e50fc 0x199a35d64 0x182ad0adc 0x1829a30cc 0x18298ed90 0x1829c8508 0x18fd95468 0x18fd951c0 0x18fe1b82c 0x18fe1b380 0x1901932c0 0x18fa41114 0x18fe69850 0x18fa1ebe4 0x18fa1e1f4 0x18d2d6e44 0x18d2d7fb4 0x1812070d0 0x181217d90 0x181152098 0x1811578a4 0x18116b468 0x19cd0f38c 0x183b0e5d0 0x18388cf74 0x188e2a314 0x188d59508 0x188d3acb8 0x104f080d4 0x104f0818c 0x10510daa4)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<WKWebView: 0x106025e00; frame = (0 0; 428 796); layer = <CALayer: 0x283bb1b80>>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: URL
Observed object: <WKWebView: 0x106025e00; frame = (0 0; 428 796); layer = <CALayer: 0x283bb1b80>>
Change: {
kind = 1;
new = "https://www.runixcoin.com/dashboard/auth-password-basic.php";
}
Context: 0x0'
terminating with uncaught exception of type NSException
(lldb)

Swift getting Nil when attempting to get value

Im not sure why i am getting this nil error on optional when attempting to print. Can somebody provide any input? It doesn't make sense that I am able to output the value from the aplicationContext, however when I attempt to get value from applicationContext["hearRate"] i get nil.
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
print("didReceiveApplicationContext\n\t\(applicationContext)")
let hrValue = applicationContext["heartRate"] as? String
print(applicationContext["hearRate"])
print(hrValue)
//heartRate.text = hrValue
}
console - output
2021-03-10 18:41:04.623716-0700 Trainer+[1824:759737] Metal API Validation Enabled
session active state
didReceiveApplicationContext
["heartRate": 00BPM]
nil
Optional("00BPM")
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file Trainer_/ViewController.swift, line 57
2021-03-10 18:41:04.999001-0700 Trainer+[1824:759754] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file Trainer_/ViewController.swift, line 57
Update - Ignore typo, found issue with IBOutlet
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
print("didReceiveApplicationContext\n\t\(applicationContext)")
let hrValue = applicationContext["heartRate"] as? String
print(applicationContext["heartRate"])
print(hrValue)
//heartRate.text = hrValue
heartRate.text = "test"
}
2021-03-11 12:45:05.482464-0700 Trainer+[1873:817768] Metal API Validation Enabled
session active state
didReceiveApplicationContext
["heartRate": 91BPM]
Optional(91BPM)
Optional("91BPM")
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file Trainer_/ViewController.swift, line 58
2021-03-11 12:45:05.887523-0700 Trainer+[1873:817966] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file Trainer_/ViewController.swift, line 58
the func session(didReceiveApplicationContext), from watchconnectivity is working as intended. I believe that my problem comes from me moving the heartRate label to a 'view container'. I added the watchconnectivity at the same time that I moved the label and assumed that it would work.
This may require a different question, not sure, how can i pass data along multiple view controllers that are visible at the same time. Since I am creating the session on the ViewController, I don't yet know how to pass the data to other view controllers without passing a full 'self' reference of the ViewController, to the DetailViewController. Coming from Java and PHP, i feel like this is not good coding practice.
I am thinking about extensions/delegates, and prototypes. I understand them to a slight degree, but I am currently working on an app and my main goal is to have a working prototype. I'll come back and refactor the code fix and fix any gaping vulnerabilities. If any body with experience can provide me with any reliable resources. Tired of hitting the next page of google as i cant find the answers that I am looking for lol.
Update #3
class ViewController: UIViewController, WCSessionDelegate {
#IBOutlet weak var cont: DetailViewController!
override func viewDidLoad() {
super.viewDidLoad()
if WCSession.isSupported() {
connectivitySession = WCSession.default
connectivitySession?.delegate = self
connectivitySession?.activate()
}
}
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
print("didReceiveApplicationContext\n\t\(applicationContext)")
let hrValue = applicationContext["heartRate"] as? String
print(applicationContext["heartRate"])
print("container\n\t\(cont.heart.text)")
cont.heart.text = "test"
}
******
}
// class assigned to 'view container' in ViewController in SB
class DetailViewController: UIView {
#IBOutlet weak var heart: UILabel!
// #IBOutlet weak var hearRate: UILabel!
#IBOutlet weak var sessionTimer: UILabel!
#IBOutlet weak var currentActivity: UILabel!
#IBOutlet weak var startButton: UIButton!
#IBOutlet weak var activityTimer: UILabel!
}
Output
2021-03-11 15:22:15.294727-0700 Trainer+[1938:854826] Metal API Validation Enabled
2021-03-11 15:22:15.628977-0700 Trainer+[1938:854826] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Trainer_.ViewController 0x102e04ec0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key menuContainer.'
*** First throw call stack:
(0x1986ad9d8 0x1aca33b54 0x1985be6e4 0x19986aca8 0x19a84f6a4 0x19ab5f254 0x198598298 0x19ab5b218 0x19a856d88 0x19a857114 0x19a8577e8 0x19af56448 0x19af55c5c 0x19af56af0 0x19af67730 0x19b17aba0 0x19a434be4 0x19af19ca0 0x19af1a044 0x19aa59ab8 0x1a79d7704 0x1a79ff130 0x1a79e4e60 0x1a79fee44 0x101291528 0x1012949f0 0x1a7a23e60 0x1a7a23b28 0x1a7a23ffc 0x19862dbf0 0x19862daf0 0x19862ce9c 0x1986273e0 0x198626ba0 0x1af38f598 0x19af182f4 0x19af1d874 0x1abda7b54 0x100f75a08 0x100f75980 0x100f75a4c 0x198305568)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Trainer_.ViewController 0x102e04ec0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key menuContainer.'
terminating with uncaught exception of type NSException
(lldb)
answered my own question, by chaning from uiviewcontroller to name of custom class.
This is for a basic watch connection session for iphone that uses multiple view controllers on same screen.
Delegates, extensions, etc, is not required. Will need to setup your segue, secondary controller, and connections.
class ViewController: UIViewController, WCSessionDelegate {
var variable: Any? // Your variable type
var sessionVariable: WCSession?
var secondVC: SecondViewController!
override func viewDidLoad() {
super.viewDidLoad()
// start session
if WCSession.isSupported() {
sessionVariable = WCSession.default
sessionVariable?.delegate = self
sessionVariable?.activate()
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// using segue.identifier, save live ViewController to your variable
if segue.identifier == "Storyboard Segue Identifier" {
if let destinationVC = segue.destination as? SecondViewController {
secondVC = destinationVC
}
}
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
print("session active state")
}
//using dispatchqueue, to update label on main thread, use self.secondVC.variable to update.
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
let contextValue = applicationContext["context"] as? String
DispatchQueue.main.async {
self.secondVC.variable.text = contextValue
}
}
}
class HealthViewController: UIViewController {
#IBOutlet weak var varialble: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
}

IKScannerDeviceViewDelegate never called

Probably a dumb question but I cannot figure how make it work. When I press scan button in my IKScannerDeviceView scan works but its delegate never gets called.
I put a breakpoint on line
print("Did scan to: \(url.path)")
Scan file appears in selected folder without problems but it never stops on breakpoint.
Am I missing something?
Just for the sake of completeness I'm using Xcode 12.2 on macOS 11.0.1
Here is my code:
import Cocoa
import ImageCaptureCore
import Quartz
class ViewController: NSViewController {
#IBOutlet weak var scannerView: IKScannerDeviceView!
var deviceBrowser:ICDeviceBrowser!
override func viewDidLoad() {
super.viewDidLoad()
self.scannerView.delegate = self
self.scannerView.mode = .advanced
self.scannerView.transferMode = .fileBased
self.deviceBrowser = ICDeviceBrowser()
self.deviceBrowser.delegate = self
self.deviceBrowser.browsedDeviceTypeMask = ICDeviceTypeMask(rawValue:
ICDeviceLocationTypeMask.local.rawValue |
ICDeviceLocationTypeMask.shared.rawValue |
ICDeviceLocationTypeMask.bonjour.rawValue |
ICDeviceLocationTypeMask.remote.rawValue |
ICDeviceLocationTypeMask.bluetooth.rawValue |
ICDeviceTypeMask.scanner.rawValue)!
self.deviceBrowser.start()
}
}
extension ViewController : IKScannerDeviceViewDelegate {
func scannerDeviceView(_ scannerDeviceView: IKScannerDeviceView!, didScanTo url: URL!, error: Error!) {
print("Did scan to: \(url.path)")
}
}
extension ViewController: ICDeviceBrowserDelegate {
func deviceBrowser(_ browser: ICDeviceBrowser, didAdd device: ICDevice, moreComing: Bool) {
if (device.type.rawValue & ICDeviceTypeMask.scanner.rawValue) == ICDeviceType.scanner.rawValue {
self.scannerView.scannerDevice = (device as! ICScannerDevice)
}
}
func deviceBrowser(_ browser: ICDeviceBrowser, didRemove device: ICDevice, moreGoing: Bool) {
device.requestCloseSession()
}
func didRemoveDevice(device: ICDevice) {
device.requestCloseSession()
}
func device(device: ICDevice, didEncounterError error: NSError?) {
print("Error")
print(error?.description ?? "----")
}
}
Apparently the following methods are not called:
func scannerDeviceView(IKScannerDeviceView!, didScanTo: ICScannerBandData!, scanInfo: [AnyHashable : Any]!, error: Error!)
func scannerDeviceView(IKScannerDeviceView!, didScanTo: URL!, error: Error!)
Implement the following method instead:
func scannerDeviceView(IKScannerDeviceView!, didScanTo: URL!, fileData: Data!, error: Error!)

iOS 10 - NSKeyValueObservation crash on deinit

I'm using NSKeyValueObservation to observe properties in a subclass ofWKWebView.
It works well on iOS 11, but crashes on deinit on iOS 10.
Printed Error Log on Console
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x15209e600 of class Rakuemon.WebView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x170232da0> (
<NSKeyValueObservance 0x170259bf0: Observer: 0x17027d500, Key path: loading, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x170643ba0>
<NSKeyValueObservance 0x170643480: Observer: 0x170c72f80, Key path: estimatedProgress, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x170643330>
<NSKeyValueObservance 0x170642c70: Observer: 0x17086c0c0, Key path: title, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x1706437b0>
)'
Codes
class WebView: WKWebView {
// MARK: - Properties
weak var delegate: WebViewDelegate?
// MARK: - Private properties
private var contentSizeObserver: NSKeyValueObservation?
private var loadingObserver: NSKeyValueObservation?
private var estimatedProgressObserver: NSKeyValueObservation?
private var titleObserver: NSKeyValueObservation?
// MARK: - Life cycle
override init(frame: CGRect, configuration: WKWebViewConfiguration) {
super.init(frame: frame, configuration: configuration)
setupObserver()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
// MARK: - Private functions
private extension WebView {
func setupObserver() {
contentSizeObserver = scrollView.observe(\.contentSize, options: [.old, .new], changeHandler: { [unowned self] _, change in
guard let oldSize = change.oldValue, let newSize = change.newValue, oldSize != newSize else { return }
self.delegate?.webView?(self, didChangeSizeFrom: oldSize, to: newSize)
})
loadingObserver = observe(\.isLoading, changeHandler: { [unowned self] _, _ in
self.delegate?.webViewIsLoading?(self)
})
estimatedProgressObserver = observe(\.estimatedProgress, options: [.new], changeHandler: { [unowned self] _, change in
guard let newValue = change.newValue else { return }
self.delegate?.webView?(self, didChangeEstimatedProgress: newValue)
})
titleObserver = observe(\.title, options: [.new], changeHandler: { [unowned self] _, change in
guard let title = change.newValue else { return }
self.delegate?.webView?(self, didChangeTitle: title ?? "")
})
}
}
Question
I also found the contentSizeObserver, which observed scrollView.contentSize, not properties of self, didn't caused crash.
So, what is the proper way to observe self's properties on iOS 10 through NSKeyValueObservation? or unregister it?
Updated on 2019/10/16
This seems to still happen on iOS 10.3 with Xcode 11 and Swift 5.1, I created a sample project to test it by using code from SR-5752.
The easiest way I figure out so far is like so:
// Environment: Xcode 11.1, Swift 5.1, iOS 10.3
deinit {
if #available(iOS 11.0, *) {} else if let observer = observer {
removeObserver(observer, forKeyPath: "foo")
}
}
Can notice that I only call removeObserver(_:forKeyPath) on iOS 10 and lower because as Stacy Smith mentioned, this crash on iOS 13 (can be reproduced easily in the sample project).
I also tried Bryan Rodríguez's suggestion, but without luck. Maybe I missed something? 🤔
// Environment: Xcode 11.1, Swift 5.1, iOS 10.3
deinit {
// Also tried only either one, no luck
self.observer?.invalidate()
self.observer = nil
}
Looks like apple bug – https://bugs.swift.org/browse/SR-5816
This is happening because NSKeyValueObservation holds a weak reference to an object. That weak reference turns to nil too soon.
In some cases workaround can be found by using lifecycle methods (viewDidDissapear and such).
In other cases you should use old obj-c api (addObserver / removeObserver / observeValue) to support iOS 10.
This worked for me:
deinit {
titleObserver = nil
}

dyld: Library not loaded: #rpath/CoreNFC.framework/CoreNFC, iOS11 and Xcode 9 beta

I get this error and app get crash while run CoreNFC sample code in Xcode 9.0 beta 2
dyld: Library not loaded: #rpath/CoreNFC.framework/CoreNFC
Referenced from: /var/containers/Bundle/Application/2837709C-C852-4811-B696-38F2725554D4/iOS-11-by-Examples.app/iOS-11-by-Examples
Reason: image not found
Does anyone knows how to fix this?
I combined some answers together to fix this thanks to #Chinchan Zu's comment
here is how to mark Core NFC as Optional stackoverflow question
First you make import to NFCCore in "Linked Frameworks and Libraries" as optional as in this screenshot
Then inside your code you wrap your code with this #if check. Here is the class I used
#if canImport(CoreNFC)
import Foundation
import CoreNFC
#endif
class NFCManagar: NSObject {
#if canImport(CoreNFC)
var session: NFCNDEFReaderSession?
#endif
var items = [Item]()
var completion: ((_ success: Bool, _ error: Error?)-> Void)?
func beginScanning(items: [Item], completion: #escaping (_ success: Bool, _ error: Error?)-> Void) {
self.completion = completion
self.items.removeAll()
self.items.append(contentsOf: items)
#if canImport(CoreNFC)
session = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: true)
session?.alertMessage = "Hold your iPhone near check in/out device."
session?.begin()
#endif
}
}
#if canImport(CoreNFC)
extension NFCManagar: NFCNDEFReaderSessionDelegate {
// MARK: - NFCNDEFReaderSessionDelegate
/// - Tag: processingTagData
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
debugPrint("Nfc is detected")
}
/// - Tag: endScanning
func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
// Check the invalidation reason from the returned error.
if let readerError = error as? NFCReaderError {
// Show an alert when the invalidation reason is not because of a success read
// during a single tag read mode, or user canceled a multi-tag read mode session
// from the UI or programmatically using the invalidate method call.
if (readerError.code != .readerSessionInvalidationErrorFirstNDEFTagRead)
&& (readerError.code != .readerSessionInvalidationErrorUserCanceled) {
debugPrint("Nfc didInvalidateWithError \(error)")
}
}
// A new session instance is required to read new tags.
self.session = nil
}
}
#endif
CoreNFC is only available on iPhone 7 and iPhone 7 Plus devices. Make sure you're running your code on one of those.
See the WWDC session and the relevant documentation for more information.
https://developer.apple.com/videos/play/wwdc2017/718/
https://developer.apple.com/documentation/corenfc
For Xcode 11 make CoreNFC.framework "Do not Embed". And also wrap your code with #if check.