Swift and Xcode Thread 1: signal SIGABRT error on YPDrawSignatureView - digital-signature

I try to use the YPDrawSignatureView for make an eSignature to my Swift 3.3 project with Xcode 9.3 version.
First I pulled the YPDrawSignatureView.swift to my project.
After I made two buttons and an UIImage to Main.storyboard. These objects pulled to my ViewController.swift and finally I have written my sample code in ViewController.swift:
import UIKit
class ViewController: UIViewController, YPSignatureDelegate {
#IBOutlet weak var signatureView: YPDrawSignatureView!
// Function for clearing the content of signature view
#IBAction func clearSignature(_ sender: UIButton) {
// This is how the signature gets cleared
self.signatureView.clear()
}
// Function for saving signature
#IBAction func saveSignature(_ sender: UIButton) {
// Getting the Signature Image from self.drawSignatureView using the method getSignature().
if let signatureImage = self.signatureView.getSignature(scale: 10) {
// Saving signatureImage from the line above to the Photo Roll.
// The first time you do this, the app asks for access to your pictures.
UIImageWriteToSavedPhotosAlbum(signatureImage, nil, nil, nil)
// Since the Signature is now saved to the Photo Roll, the View can be cleared anyway.
self.signatureView.clear()
}
}
// didStart() is called right after the first touch is registered in the view.
// For example, this can be used if the view is embedded in a scroll view, temporary
// stopping it from scrolling while signing.
func didStart() {
print("Started Drawing")
}
// didFinish() is called rigth after the last touch of a gesture is registered in the view.
// Can be used to enabe scrolling in a scroll view if it has previous been disabled.
func didFinish() {
print("Finished Drawing")
}
override func viewDidLoad() {
super.viewDidLoad()
signatureView.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
And when I tried to run my app, I got an error message from Xcode:
And here is the output window:
2018-04-04 10:57:17.936377+0200 Alairas3[413:70689] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key clearSignature.'
* First throw call stack:
(0x183496d8c 0x1826505ec 0x1834969f0 0x183dec44c 0x18d5085d4 0x18d94ba08 0x1833a4b24 0x18d6d90e4 0x18d50aadc 0x18d14e0f0 0x18d072b90 0x18d072acc 0x18d063d60 0x18d062b94 0x18d0f06a8 0x18d0662f0 0x18d03365c 0x18d663a0c 0x18d032e4c 0x18d032ce8 0x18d031b78 0x18dcc772c 0x18d031268 0x18daac9b8 0x18dbfaae8 0x18d030c88 0x18d030624 0x18d02d65c 0x18d02d3ac 0x185c94470 0x185c9cd6c 0x101735220 0x101741850 0x185cc8878 0x185cc851c 0x185cc8ab8 0x18343f404 0x18343ec2c 0x18343c79c 0x18335cda8 0x18533f020 0x18d33d78c 0x1009b0ae4 0x182dedfc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
Please, help me, what is wrong?

Related

SwiftUI. Access to properties from background

This problem is driving me crazy.
In principle the code below works correctly.
The authenticator that is called is a class defined in its own module (Authenticator.swift).
The code below is a method of the viewModel that conforms ObservableObject protocol.
The observed properties self.error and self.goToHomeView are properties published from the viewModel.
The authenticator method authenticates with FaceID. If authentication succeeds, error is nil, then the observed variable goToHomeView is set to true to switch to the Home view.
If error is not nil, then self.error is assigned which is of type LocalizedError and that triggers an alert in the view.
The problem is that an annoying warning appears all the time saying: "Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.”
I would like to know if anyone knows a technically valid way to modify values from the main thread from a secondary thread running in background.
Task {
await authenticator.authenticate { error in
if let error = error {
self.error = error
} else {
self.goToHomeView = true
}
}
}

Passing data to Flutter based on Android event

Really struggling with the correct way to achieve the following. If I want to make a native call to Android FROM my Flutter app, there are plenty of examples that I can follow. eg: create an EventChannel and then listen for events and respond to requests from within my Android/Kotlin onMessage listener.
However, what I cannot figure out is how to go the other way! I have a native event that is triggering in the background within native Android. When the event occurs, everything works fine and I can print / debug the data, but I cannot figure out the correct way to package this data up and send back up to Flutter to display in the app:
class MainActivity: FlutterActivity() {
....
....
....
fun somethingHappened(firstName: String, lastName: String, eMail: String) {
Log.d("MyApp","An event has occurred...");
// Log message is printing out correctly, but need to
// create Object / Hashmap / data structure and send to Flutter
}
....
....
}
Can anyone tell me the correct pattern / approach to use and ideally a link to a simple example that I can reference?
Thanks,
Jab
In MainActivity:
class MainActivity: FlutterActivity() {
private val CHANNEL = "CHANNEL"
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
val channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL);
channel.invokeMethod("nameOfMethod", "dataToPass")
}
}
and on flutter side:
MethodChannel channel = MethodChannel('CHANNEL');
#override
void initState() {
channel.setMethodCallHandler((call){
if(call.method == 'nameOfMethod'){
print(call.arguments);
}
return null;
});
super.initState();
}

passing around NSManagedObjects

I get strange errors when I am trying to pass around NSManagedObject through several functions. (all are in the same VC).
Here are the two functions in question:
func syncLocal(item:NSManagedObject,completionHandler:(NSManagedObject!,SyncResponse)->Void) {
let savedValues = item.dictionaryWithValuesForKeys([
"score",
"progress",
"player"])
doUpload(savedParams) { //do a POST request using params with Alamofire
(success) in
if success {
completionHandler(item,.Success)
} else {
completionHandler(item,.Failure)
}
}
}
func getSavedScores() {
do {
debugPrint("TRYING TO FETCH LOCAL SCORES")
try frc.performFetch()
if let results = frc.sections?[0].objects as? [NSManagedObject] {
if results.count > 0 {
print("TOTAL SCORE COUNT: \(results.count)")
let incomplete = results.filter({$0.valueForKey("success") as! Bool == false })
print("INCOMPLETE COUNT: \(incomplete.count)")
let complete = results.filter({$0.valueForKey("success") as! Bool == true })
print("COMPLETE COUNT: \(complete.count)")
if incomplete.count > 0 {
for pendingItem in incomplete {
self.syncScoring(pendingItem) {
(returnItem,response) in
let footest = returnItem.valueForKey("player") //only works if stripping syncScoring blank
switch response { //response is an enum
case .Success:
print("SUCCESS")
case .Duplicate:
print("DUPLICATE")
case .Failure:
print("FAIL")
}
}
} //sorry for this pyramid of doom
}
}
}
} catch {
print("ERROR FETCHING RESULTS")
}
}
What I am trying to achieve:
1. Look for locally saved scores that could not submitted to the server.
2. If there are unsubmitted scores, start the POST call to the server.
3. If POST gets 200:ok mark item.key "success" with value "true"
For some odd reason I can not access returnItem at all in the code editor - only if I completely delete any code in syncLocal so it looks like
func syncLocal(item:NSManagedObject,completionHandler:(NSManagedObject!,SyncResponse)->Void) {
completionHandler(item,.Success)
}
If I do that I can access .syntax properties in the returning block down in the for loop.
Weirdly if I paste the stuff back in, in syncLocal the completion block keeps being functional, the app compiles and it will be executed properly.
Is this some kind of strange XCode7 Bug? Intended NSManagedObject behaviour?
line 1 was written with stripped, line 2 pasted rest call back in
There is thread confinement in Core Data managed object contexts. That means that you can use a particular managed object and its context only in one and the same thread.
In your code, you seem to be using controller-wide variables, such as item. I am assuming the item is a NSManagedObject or subclass thereof, and that its context is just one single context you are using in your app. The FRC context must be the main thread context (a NSManagedObjectContext with concurrency type NSMainThreadConcurrencyType).
Obviously, the callback from the server request will be on a background thread. So you cannot use your managed objects.
You have two solutions. Either you create a child context, do the updates you need to do, save, and then save the main context. This is a bit more involved and you can look for numerous examples and tutorials out there to get started. This is the standard and most robust solution.
Alternatively, inside your background callback, you simply make sure the context updates occur on the main thread.
dispatch_async(dispatch_get_main_queue()) {
// update your managed objects & save
}

HaxeFlixel - issue with passing FlxTypedGroup into another FlxState

After passing FlxTypedGroup into new FlxState im getting this error message from new state :
Invalid field access : length
my code :
in GameState class after certain action:
FlxG.switchState(new EvaluationState(ingredients));
please note that ingredients is FlxTypedGroup<Ingredient> and its not empty.
in EvaluationState :
var ingredients:FlxTypedGroup<Ingredient>;
public function new(i:FlxTypedGroup<Ingredient>)
{
super();
ingredients = i;
}
override public function create():Void
{
super.create();
for (ing in ingredients)
{
trace(ing.active);
}
}
Also im getting null in create() function after calling ingredients.members.
Does anyone know how to pass FlxTypedGroup into new FlxState without destroying it ?
It seems that your group is being destroyed in another state when the switch occurs.
How is the previous state in which "ingredients" is created? If the group is added to this last state the most likely cause is that when switching it calls "destroy()" on ingredients.
Try to remove it from the state before passing is as parameter to EvaluationState to see if this solves your problem.
currentState.remove(ingredients); //This should prevent a null members
FlxG.switchState(new EvaluationState(ingredients));

Invalid layout resources

Sometimes when my Xamarin.Android app gets killed and the application needs to recreate its main activity some layouts are not available and the screen displays no views.
By pressing the device back button and then reopening the application, its main activity gets correctly instantiated and displayed.
This is the code responsible for loading the used layouts:
// Returns null whenever trying to recreate views right after the application got killed by Android (Due to some multi-tasking reasons). Otherwise, it returns valid instances.
var layout = DroidResources.LoadLayout (context, parent, layoutName);
See next screenshots (texts were omitted):
Before/after the system automatically recreates the activity.
I am using:
Xamarin.Android 4.10
MvvmCross 3.0.13 - Android.Dialog
May some of you point me a direction about how can I fix this issue?
I am new to both described technologies. Any help will be appreciated.
Logs retrieved from the DDMS application:
E/Android.Dialog(9171): LoadLayout failed: You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
E/Android.Dialog(9171): LoadLayout failed: You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
E/Android.Dialog(9171): LoadLayout failed: You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
E/Android.Dialog(9171): LoadLayout failed: You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
E/Android.Dialog(9171): LoadLayout failed: You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
E/Android.Dialog(9171): LoadLayout failed: You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
E/Android.Dialog(9171): ViewElement: Failed to load resource: MenuSeparator
E/Android.Dialog(9171): LoadLayout failed: You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
E/Android.Dialog(9171): LoadLayout failed: You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
E/Android.Dialog(9171): LoadLayout failed: You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
E/Android.Dialog(9171): ViewElement: Failed to load resource: MenuSeparator
I would like to understand why the DroidResources class was initialized when normally opening the application but it is not initialized when the application is just returning from the background. I guess during the background time Android forced its instance to be garbage collected but not the entire application.
I also think I may be wrongly initializing it, that is my Setup.cs file:
/// <summary>
/// MvvmCross setup class.
/// Allows Android.Dialog usage during application lifecycle
/// </summary>
public class Setup : MvxAndroidDialogSetup
{
public Setup (Context applicationContext)
: base (applicationContext)
{
}
protected override IMvxApplication CreateApp ()
{
return new MvvmCrossApplication ();
}
}
// MvvmCross internal application.
public class MvvmCrossApplication : MvxApplication
{
public override void Initialize ()
{
// Setup initial application view which will be loaded as soon as the MvvmCross framework
// initialization has been completed.
RegisterAppStart<ApplicationViewModel>();
}
}
//
// These next classes ApplicationViewModel and ApplicationView are auxiliary classes
// needed by the MvvmCross framework to ensure that others application classes are loaded
// only after the MvvmCross initilization has been completed.
public class ApplicationViewModel : MvxViewModel
{
}
[Activity (Theme = "#style/Theme.Transparent", NoHistory = true)]
public class ApplicationView : MvxActivity
{
protected override void OnResume ()
{
base.OnResume ();
// Start the application main activity.
StartActivity (typeof(ApplicationMainActivity));
}
}
Until now I am just using the Android.Dialog dlls from the MvvmCross library. But I am going to start accordingly using ViewModels as soon as possible.
Here follows the ApplicationMainActivity source code:
/// <summary>
/// Application activity.
/// </summary>
/// <remarks>A transparent activity used to recreate current application screens workflow.</remarks>
[Activity (Theme = "#style/Theme.Transparent", NoHistory = true)]
public class ApplicationMainActivity : ClientUserActivity
{
#region Lifecycle methods
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
if (ClientUser.IsLoggedIn ()) {
if (ClientUser.ShouldShowWizard ()) {
// Show the wizard screen
StartActivity (wizardActivity);
} else {
// Show the main menu screen
StartActivity (typeof(NavigationDrawerActivity));
}
} else {
// Show the welcome screen
StartActivity (typeof(WelcomeActivity));
}
}
...
As you post layer-upon-layer of code in this question, I'm getting increasingly more confused about whether you are actually using MvvmCross.
If you are just using the MvvmCross Android.Dialog port - and not using MvvmCross - then you need to find a way to do for what the error message is asking you to do:
You must call DroidResources.Initialize(Resource.Layout) before using Dialogs
In a "normal" MvvmCross application, this problem is avoided because any MvxActivity will ensure Setup is created and initialised before OnCreate is complete - and Setup includes:
protected virtual void InitializeDialogBinding()
{
var finder = Mvx.Resolve<IMvxAppResourceTypeFinder>();
var resourceType = finder.Find();
var nestedResourceType = resourceType.GetNestedTypes().FirstOrDefault(x => x.Name == "Layout");
DroidResources.Initialize(nestedResourceType);
}
see https://github.com/MvvmCross/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Dialog.Droid/MvxAndroidDialogSetup.cs#L40
If you want to implement non-MvxActivity Activities, then you'll need to find some other way to ensure setup is started and/or droid resources are loaded.

Resources