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

iOS Plugins Fail with Objective C and Swift Channels #24171

Closed
jrmarkham opened this Issue Nov 9, 2018 · 9 comments

Comments

Projects
None yet
3 participants
@jrmarkham
Copy link

jrmarkham commented Nov 9, 2018

iOS Plugins Fail with Objective C and Swift Channels
// Rebuilds are here
https://github.com/jrmarkham/flutter_plugins_objc
https://github.com/jrmarkham/flutter_plugins_swift

Tech Specs: 
MacOS: 10.14.1
Flutter (Channel master, v0.11.1-pre.80, on Mac OS X 10.14.1 18B75, locale
    en-US)
    • Flutter version 0.11.1-pre.80 at /usr/local/lib/flutter
    • Framework revision 48c00dc7d7 (3 days ago), 2018-11-06 12:32:35 -0800
    • Engine revision fb5b097e5c
    • Dart version 2.1.0 (build 2.1.0-dev.8.0 bf26f760b1)

IDEs: Intellij Ultimate 2018.2.5

I have found that developing channels with Objective C and Swift that are using packages (that are object C) causes issues. I built 2 identical projects with 2 plugins (image picker and URL launcher) both projects work (plugins work as expected) before the channel is added.

In the both Objective C and Swift app once the channel is added; the plugins fail but the channel does work— I have them just returning a boolean in both.

IntelliJ
On builds from IntelliJ the following error freeze the app:

// OBJECTIVE C

exception = {MissingPluginException} MissingPluginException(No implementation found for method canLaunch on channel plugins.flutter.io/url_launcher)
 message = "No implementation found for method canLaunch on channel plugins.flutter.io/url_launcher"
method = "canLaunch"
this = {MethodChannel} 
arguments = {_InternalLinkedHashMap} size = 1
result = null
exception = {MissingPluginException} MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker)
method = "pickImage"
this = {MethodChannel} 
arguments = {_InternalLinkedHashMap} size = 3
result = null

// SWIFT

exception = {MissingPluginException} MissingPluginException(No implementation found for method canLaunch on channel plugins.flutter.io/url_launcher)
method = "canLaunch"
this = {MethodChannel} 
arguments = {_InternalLinkedHashMap} size = 1
result = null
exception = {MissingPluginException} MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker)
method = "pickImage"
this = {MethodChannel} 
arguments = {_InternalLinkedHashMap} size = 3
result = null
@zoechi

This comment has been minimized.

Copy link
Contributor

zoechi commented Nov 11, 2018

Please add the output of flutter doctor -v.

@jrmarkham

This comment has been minimized.

Copy link
Author

jrmarkham commented Nov 11, 2018

Well I have tried all channels: master/dev/beta -- I used dev the most so here’s that one:

plugins_swift > flutter doctor -v
[✓] Flutter (Channel dev, v0.11.3, on Mac OS X 10.14.1 18B75, locale en-US)
    • Flutter version 0.11.3 at /usr/local/lib/flutter
    • Framework revision 72bf075e8d (2 days ago), 2018-11-09 20:36:17 -0800
    • Engine revision 5646e86a6f
    • Dart version 2.1.0 (build 2.1.0-dev.9.3 9c07fb64c4)

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

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 2.0.0
    • CocoaPods version 1.6.0.beta.1

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 30.0.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] IntelliJ IDEA Ultimate Edition (version 2018.2.5)
    • IntelliJ at /Users/johnmarkham/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 30.0.2
    • Dart plugin version 182.5124

[✓] Connected device (2 available)
    • JM iPhone X   • fb23caaec4bfc8e2ad73ab81cb5717a370687766 • ios • iOS 12.1.1
    • iPhone XS Max • 347C2D03-F79A-4C35-905A-6DBBE68871AB     • ios • iOS 12.1 (simulator)

• No issues found!
@jrmarkham

This comment has been minimized.

Copy link
Author

jrmarkham commented Nov 11, 2018

Let me know if you need others-- I happy to help you guys fix these channel / plugin conflicts.

@dnfield

This comment has been minimized.

Copy link
Member

dnfield commented Nov 18, 2018

You removed this line from AppDelegate.m, which registers plugins:

  [GeneratedPluginRegistrant registerWithRegistry:self];

Add it back and everything's good, e.g.

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;

    FlutterMethodChannel* batteryChannel = [FlutterMethodChannel
                                           methodChannelWithName:@"com.channels/test"
                                           binaryMessenger:controller];

    [batteryChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result){
        if([@"test" isEqualToString:call.method]){
            BOOL res = [self channelTest];
            if(!res){
                result([FlutterError errorWithCode:@"UNAVAILABLE"
                                           message:@"test fail"
                                           details:nil]);
            }else{
                result(@"test worked");
            }

        }else{
            result(FlutterMethodNotImplemented);
        }
    }];
  [GeneratedPluginRegistrant registerWithRegistry:self];

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@dnfield dnfield self-assigned this Nov 18, 2018

@dnfield

This comment has been minimized.

Copy link
Member

dnfield commented Nov 18, 2018

I'm going to close this for now - when I add this back on your demo repo, everything's working fine. Please feel free to reopen if you feel like this hasn't addressed your issue, or open a new issue if there's some other problem at play here!

@dnfield dnfield closed this Nov 18, 2018

@jrmarkham

This comment has been minimized.

Copy link
Author

jrmarkham commented Nov 18, 2018

Yup I see.....Thanks. Where/what would I add for the swift build?

FYI: I copied that code block from the flutter channel so you may want to update that as well.
https://flutter.io/docs/development/platform-integration/platform-channels

@dnfield

This comment has been minimized.

Copy link
Member

dnfield commented Nov 18, 2018

I'll reopen this to track fixing the docs.

For Swift it should be GeneratedPluginRegistrant.register(with: self)

@dnfield dnfield reopened this Nov 18, 2018

dnfield added a commit to flutter/website that referenced this issue Nov 18, 2018

Platform channels and generated plugins
Fixes flutter/flutter#24171

Docs are fine for Android, but were missing these lines for iOS.

/cc @jrmarkham
@jrmarkham

This comment has been minimized.

Copy link
Author

jrmarkham commented Nov 19, 2018

Thanks Dan. I’ll test Swift later... ObjectiveC worked just fine.

@jrmarkham

This comment has been minimized.

Copy link
Author

jrmarkham commented Nov 19, 2018

Swift verified too, thanks.

sfshaza2 added a commit to flutter/website that referenced this issue Nov 19, 2018

Platform channels and generated plugins (#1751)
* Platform channels and generated plugins

Fixes flutter/flutter#24171

Docs are fine for Android, but were missing these lines for iOS.

/cc @jrmarkham

* Update platform-channels.md

* Update platform-channels.md

* Update platform-channels.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.