ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

How to Add an iOS Native Framework in the Flutter Project?

Home / Article & Blogs / Web Design / Mobile Development / How to Add an iOS Native Framework in the Flutter Project?
By Satishkumar Raparthi inMobile Development, Web Design

Nowadays, the majority of mobile apps are developed using cross-platform frameworks such as Flutter and React Native. When developing Flutter apps, one of the most important questions raised is how to add an iOS native framework to the Flutter project. This blog post will demonstrate the successful way to add an iOS native framework to your Flutter project.

Features

Card91 SDK, which provides you with basic details of the card, and in return, the package displays the card details.

Getting started

Open the iOS folder in the React Native project with Xcode.

Folder: {YourFlutterProjectName}>ios>{yourprojectname}.xcworkspace

Use this Framework as a SDK

Add your XCFramework file here by dragging and dropping it in Frameworks, Libraries, and Embedded Content.

Path: {YourFlutterProject}>iosgenerayourprojectname}.xcworkspace

Switch to AppDelegate.m in the iOS folder and import the framework and import the flutter project name as header:

AppDelegate

Import framework:
import CustomerAppIOSFramework

Usage

Add the native modules and invoke framework methods in AppDelegate  as below the implementation of AppDelegate.

Folder: FlutterProject>ios>projectname>AppDelagate

func callingCustomerAppIOSFramework () {

        let VC = LoadingVC()

        VC.number = “*******”

        VC.deviceId = “******”

        VC.sdkAuth = “*******”

        VC.env = “*******”

        UIApplication.shared.windows.first?.rootViewController = VC

        UIApplication.shared.windows.first?.makeKeyAndVisible()

    }

Flutter End:

1. Create a new app project

In a terminal run:

flutter create flutter_to_native

By default, it supports writing Kotlin and Swift. To use Java or Objective-C use command below

flutter create -i objc -a java flutter_to_native

2. Create a platform Channel

The client and host sides of the channel are connected through the channel name passed in the channel constructor. All channel names used in a single app must be unique. In our example, we are creating the channel name flutter.native/helper

class _MyHomePageState extends State<MyHomePage> {

static const platform = const MethodChannel(‘flutter.native/helper’);

3. Invoke method on platform Channel

Invoke a method on the method channel, specifying the concrete method to call via the String identifier. In the code below, it is helloFromNativeCode

String response = “”;

 try {
final String result = await  platform.invokeMethod(‘helloFromNativeCode’);
response = result;
} on PlatformException catch (e) {
response = “Failed to Invoke: ‘${e.message}’.”;
}

Use the returned response to update the user interface state inside setState.

setState(() {
_responseFromNativeCode = response;
});

4. Create method implementation in Android using java

In Android Studio open the Flutter app and select the android folder inside it. Open the file MainActivity.java

Now we have to create a MethodChannel with the same name that we have created in Flutter App.

public class MainActivity extends FlutterActivity {

 private static final String CHANNEL = “flutter.native/helper”;

We have to create a MethodCallHandler in onCreate method

new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
    new MethodChannel.MethodCallHandler() {
        @Override
        public void onMethodCall(MethodCall call, MethodChannel.Result result) {
          if (call.method.equals(“helloFromNativeCode”)) {
            String greetings = helloFromNativeCode();
            result.success(greetings);
          }
        }});

5. Create method implementation in iOS using Objective C

Open the file AppDelegate.m of your Flutter app in Xcode. Now we have to create a FlutterMethodChannel with the same name that we have created in Flutter App.

FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
      FlutterMethodChannel* nativeChannel = [FlutterMethodChannel
      methodChannelWithName:@”flutter.native/helper”
      binaryMessenger:controller];

Create method call handler

[nativeChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
    if ([@”helloFromNativeCode”  isEqualToString:call.method]) {
    NSString *strNative = [weakSelf helloFromNativeCode];
    result(strNative);
  } else {
  result(FlutterMethodNotImplemented);
}
}];

Conclusion:

In this blog, we have shown you how to add and invoke the iOS native framework to the Flutter project. Platform channels are asynchronous only. But there are quite a few platform APIs out there that make synchronous calls into your host app components, asking for information or help or offering a window of opportunity. One example is Activity.onSaveInstanceState on Android. Being synchronous means everything must be done before the incoming call returns. Now, you might like to include information from the Dart side in such processing, but it is too late to start sending out asynchronous messages once the synchronous call is already active on the main UI thread.

Additional reading: How to Add an iOS Native Framework in React Native Project? 

get in touch

flutter projectiOS native framework in the flutter project
41
Like this post
2 Posts
Satishkumar Raparthi

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • How to Add an iOS Native Framework in React Native Project?
    Previous PostHow to Add an iOS Native Framework in React Native Project?
  • Next PostAll about Salesforce’s Biggest Event Dreamforce Experience by ABSYZians.
    How to Add an iOS Native Framework in React Native Project?

Related Posts

Hive Database Integration In Flutter
Flutter Mobile Development

Hive Database Integration In Flutter

GetConnect: The best way to perform API operations in Flutter with GetX.
Flutter Mobile Development

GetConnect: The best way to perform API operations in Flutter with GetX.

Top 5 Reasons Why You Should Choose Flutter App Development?
Flutter Mobile Development

Top 5 Reasons Why You Should Choose Flutter App Development?

How to Add an iOS Native Framework in React Native Project?
Mobile Development Web Design

How to Add an iOS Native Framework in React Native Project?

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT