Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXC_BAD_ACCESS on addOrUpdate #238

Closed
KindTech opened this issue Jul 21, 2017 · 4 comments
Closed

EXC_BAD_ACCESS on addOrUpdate #238

KindTech opened this issue Jul 21, 2017 · 4 comments

Comments

@KindTech
Copy link

IOS 10.3 ionic 2 xcode 8.3.3
Location set to always
Have done conversion as described in #231

When adding a geofence, I get a warning showing in XCode:

A location manager (0x10116cf40) was created on a dispatch queue executing on a thread other than the main thread. It is the developer's responsibility to ensure that there is a run loop running on the thread on which the location manager object is allocated. In particular, creating location managers in arbitrary dispatch queues (not attached to the main queue) is not supported and will result in callbacks not being received.

Immediately after that I get a EXC_BAD_ACCESS (code:1)
at GeoNotificationManager.init()

class GeoNotificationManager : NSObject, CLLocationManagerDelegate {
    let locationManager = CLLocationManager() <--Error occurs here

Stepping up the trace leads to addOrUpdate.

Relevant code from adding geofence:

let fence:iGeofence = {
    id: this.utilityService.createGuid(),
    latitude: 39.58redacted,
    longitude:-105.37redacted,
    radius: 1000,
    transitionType: this.geofence.TransitionType.ENTER,
    notification: {
      id: this.getNextNotificationId(),
      title: "redacted",
      text: "redacted",
      icon: null,
      openAppOnClick: true,
      data:{
        reftype:"redacted",
        refid:"redacted",
        refcity:"redacted",
        refname:"redacted"
      }
    },
  };
  this.addOrUpdate(fence);
@KindTech
Copy link
Author

Update: Implementing the changes in #224 fixed the issue.

@KindTech
Copy link
Author

Ok apparently it didn't fix the issue.

@KindTech KindTech reopened this Jul 22, 2017
@KindTech
Copy link
Author

KindTech commented Aug 1, 2017

Is anybody maintaining this plugin?

@KindTech
Copy link
Author

KindTech commented Aug 4, 2017

So to fix this:
assuming you've done #231 and #224
in GeofencePlugin.swift
replace

let locationManager = CLLocationManager()

with

 let locationManager = { () -> CLLocationManager in
		// CLLocationManager must be created on main thread otherwise
		// it will generate an error at init time.
		if Thread.isMainThread {
			return CLLocationManager()
		} else {
			return DispatchQueue.main.sync {
				return CLLocationManager()
			}
		}
	 }()

@KindTech KindTech closed this as completed Aug 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant