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

[question] no such module 'background_locator' #45

Closed
moovida opened this issue Apr 24, 2020 · 10 comments
Closed

[question] no such module 'background_locator' #45

moovida opened this issue Apr 24, 2020 · 10 comments

Comments

@moovida
Copy link
Contributor

moovida commented Apr 24, 2020

Hi, I am trying to setup the lib to be used in IOS and I am probably doing something wrong.

I followed the wiki page but inside my swift file it can't load the module:

....../ios/Runner/AppDelegate.swift:3:8: error: no such module 'background_locator'
      import background_locator

When I started this, I didn't have a swift file, but Appdelegate.m and .h files and a main.
Any idea what I might be missing. Thanks a ton. Looking forward to test this library.

@mehdok
Copy link
Collaborator

mehdok commented Apr 25, 2020

You have Objective-C project, There is no need to add AppDelagate.swift. Just add the following line to your AppDelegate.m file:

#import <background_locator/BackgroundLocatorPlugin.h>

@moovida
Copy link
Contributor Author

moovida commented Apr 25, 2020

The ios part has been generated when I first started the project and I have no knowledge about it. Maybe previous Object-C were generated instead of Swift.

Anyways your suggestion worked: I placed it in the .h just because there I found imports while the .m had includes. But it should be the same I guess.

Thanks a lot!

@moovida moovida closed this as completed Apr 25, 2020
@moovida
Copy link
Contributor Author

moovida commented Apr 27, 2020

Please allow me to reopen this, since it looks related.
On IOS the app crashes at startup when trying to connect. In the crash log I find only this which seems to be related:

Thread 0 name:
Thread 0 Crashed:
0   ???                           	000000000000000000 0 + 0
1   Runner                        	0x000000010037e440 -[BackgroundLocatorPlugin handleMethodCall:result:] + 248
2   Flutter                       	0x000000010087ad20 0x1007ec000 + 584992
3   Flutter                       	0x0000000100818338 0x1007ec000 + 181048
4   Flutter                       	0x000000010086bd5c 0x1007ec000 + 523612
5   Flutter                       	0x0000000100826f58 0x1007ec000 + 241496
6   Flutter                       	0x00000001008291dc 0x1007ec000 + 250332
7   CoreFoundation                	0x00000001ba9b61c0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28 (CFRunLoop.c:1766)
8   CoreFoundation                	0x00000001ba9b5edc __CFRunLoopDoTimer + 880 (CFRunLoop.c:2357)
9   CoreFoundation                	0x00000001ba9b55b8 __CFRunLoopDoTimers + 276 (CFRunLoop.c:2512)
10  CoreFoundation                	0x00000001ba9b05c8 __CFRunLoopRun + 1640 (CFRunLoop.c:0)
11  CoreFoundation                	0x00000001ba9afc34 CFRunLoopRunSpecific + 424 (CFRunLoop.c:3192)
12  GraphicsServices              	0x00000001c4af938c GSEventRunModal + 160 (GSEvent.c:2246)
13  UIKitCore                     	0x00000001beae222c UIApplicationMain + 1932 (UIApplication.m:4820)
14  Runner                        	0x00000001003753a8 main + 88
15  libdyld.dylib                 	0x00000001ba837800 start + 4

I am quite sure I followed the instructions properly, but clearly something is off. DO you see something that might lead me to the error? Thanks a ton.

@moovida moovida reopened this Apr 27, 2020
@gpibarra
Copy link
Contributor

Are you running the project "example" inside this repository or is it a new application that you copied the configuration?

@moovida
Copy link
Contributor Author

moovida commented Apr 27, 2020

@gpibarra it is a different application inside which I am trying to use the library.


update: I have been able to successfully install the example project and run. The only difference I see is the nature of the ios part (swift vs object-c). I will investigate. Thanks for the hint.

@moovida
Copy link
Contributor Author

moovida commented Apr 28, 2020

Alright, finally been able to run my app throught Xcode on a device. I am getting this:

.pub-cache/hosted/pub.dartlang.org/background_locator-1.1.2+2/ios/Classes/BackgroundLocatorPlugin.m:169
2020-04-28 09:09:13.539639+0200 Runner[361:15753] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'failed to set registerPlugins'

So I assume I am just doing something wrong in the object-c code. Since I have no idea about what I am doing in there, I will try to post my files, since I feel something is missing:

main.m

#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char* argv[]) {
  @autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
  }
}

AppDelegate.h

#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>

@interface AppDelegate : FlutterAppDelegate

@end

AppDelegate.m

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import <background_locator/BackgroundLocatorPlugin.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];
  // Override point for customisation after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

Shouldn't I be able to call: BackgroundLocatorPlugin.setPluginRegistrantCallback(registerPlugins)
in here somehow?

@moovida
Copy link
Contributor Author

moovida commented Apr 28, 2020

Alright, I think I found a solution.

I tried to migrate the ios part to swift before but it would not find the background_locator module and therefore not build.

But then I noticed those lines where missing in my Podfile:

target 'Runner' do
  use_frameworks!                                  <-- this one
  use_modular_headers!                         <-- and this one
  # Flutter Pod

  copied_flutter_dir = File.join(__dir__, 'Flutter')

After adding those and running pod install the Pods_Runner.framework is used in the libs section and things are loaded properly.

@moovida moovida closed this as completed Apr 28, 2020
@moovida
Copy link
Contributor Author

moovida commented Apr 28, 2020

If it is of interest, I could write a small entry about this migration in the wiki setup part. Maybe another complete ignorant in ios as myself could find benefit.

@mehdok
Copy link
Collaborator

mehdok commented Apr 29, 2020

If it is of interest, I could write a small entry about this migration in the wiki setup part. Maybe another complete ignorant in ios as myself could find benefit.

You are very welcome to do that;

@moovida
Copy link
Contributor Author

moovida commented Apr 29, 2020

It is the least I can do :-)

I just noticed that there is no way to make pull requests against the wiki. I therefore attach my proposal of the setup file (zipped sine github doesn't allow md file to be uploaded):Setup.md.zip

For better readability I inverted the steps. It should not be a problem, but you better check if things look right.

Thanks!

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

3 participants