bkonyi / FlutterGeofencing

Rough work for Flutter geofencing plugin
BSD 3-Clause "New" or "Revised" License
338 stars 220 forks source link

GeofencingManager.initialize() crashing the application on iOS. #28

Closed WahibAbdul closed 4 years ago

WahibAbdul commented 4 years ago

I have copied all the code from example into a new flutter project, main file is exactly the same as example project. Added information in info.plist file but Calling GeofencingManager.initialize() is crashing application with this error but download repo example project is working fine.

*** First throw call stack: ( 0 CoreFoundation 0x00007fff23b98bde exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff503b5b20 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23b98958 +[NSException raise:format:arguments:] + 88 3 Foundation 0x00007fff255eb6f5 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191 4 Runner 0x0000000104a2fdbf -[GeofencingPlugin startGeofencingService:] + 799 5 Runner 0x0000000104a2e59b -[GeofencingPlugin handleMethodCall:result:] + 635 6 Flutter 0x0000000104b7592e 45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 104 7 Flutter 0x0000000104b0c9a4 _ZNK7flutter21PlatformMessage<…>

Flutter Doctor

[✓] Flutter (Channel beta, v1.10.7, on Mac OS X 10.14.6 18G103, locale en-US) • Flutter version 1.10.7 at /Users/wahib/flutter • Framework revision e70236e36c (6 weeks ago), 2019-10-02 09:32:30 -0700 • Engine revision 9e6314d348 • Dart version 2.6.0 (build 2.6.0-dev.0.0 1103600280)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) • Android SDK at /Users/wahib/Library/Android/sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-29, build-tools 28.0.3 • ANDROID_HOME = /Users/wahib/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.0) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 11.0, Build version 11A420a • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 38.2.3 • Dart plugin version 191.8423 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.40.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.6.0

[✓] Connected device (1 available) • iPhone 11 Pro • 52B6B926-AF1D-47E0-8A37-7A8927BC0BA0 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-0 (simulator)

• No issues found!

graperaisin1 commented 4 years ago

Did you find a solution? I'm experiencing the same issue.

WahibAbdul commented 4 years ago

Did you find a solution? I'm experiencing the same issue.

Yes. In iOS setup documentation it is missing some configuration info.

Add this line in AppDelegate.swift file. GeofencingPlugin.setPluginRegistrantCallback { (registry) in GeneratedPluginRegistrant.register(with: registry) }

And in your Bridging-Header.h file add this: #import <geofencing/GeofencingPlugin.h>

This solved my problem and everything is working perfectly now. @JFreakDK it would be nice if you can update documentation about iOS setup.

bkonyi commented 4 years ago

Sounds like you've found a solution, but let me know if there's something I'm missing here and I'll reopen.

toniree commented 4 years ago

Hi @WahibAbdul, I notice you said "AppDelegate.swift", but this library seems to be in Flutter, and the example iOS plugin code seems to use Objective-C. Is this an original AppDelegate.swift that you wrote? Or am I missing something?

jjakob666 commented 4 years ago

Hi @WahibAbdul, I notice you said "AppDelegate.swift", but this library seems to be in Flutter, and the example iOS plugin code seems to use Objective-C. Is this an original AppDelegate.swift that you wrote? Or am I missing something?

, yes but in flutter in the ios folder you have AppDelegate.swift. it's pretty empy but go ahead and make changes as per this thread and it will stop the crashing and work.

zubairehman commented 4 years ago

@toniree for objective c you can copy and paste the code below:

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"

#import <geofencing/GeofencingPlugin.h>

void registerPlugins(NSObject<FlutterPluginRegistry>* registry) {
    if( ![registry hasPlugin:@"io.flutter.plugins.geofencing"] ) {
      [GeofencingPlugin registerWithRegistrar:[registry registrarForPlugin:@"io.flutter.plugins.geofencing"]];
    }
}

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];
  [GeofencingPlugin setPluginRegistrantCallback:registerPlugins];

  // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end