Flutter - Writing IOS Specific Code كتابة كود خاص بنظام هاتف ايفون من خلال فلاطر الرفرفة

 Flutter - Writing IOS Specific Code كتابة كود خاص بنظام هاتف ايفون من خلال فلاطر الرفرفة

Flutter - Writing IOS Specific Code كتابة كود خاص بنظام هاتف ايفون من خلال فلاطر الرفرفة


Flutter - Writing IOS Specific Code كتابة كود خاص بنظام هاتف ايفون من خلال فلاطر الرفرفة 

يشبه الوصول إلى رمز خاص بنظام iOS ذلك الموجود على

Flutter - Writing IOS Specific Code كتابة كود خاص بنظام هاتف ايفون من خلال فلاطر الرفرفة Flutter  نظام Android الأساسي باستثناء أنه يستخدم لغات محددة لنظام iOS - Objective-C أو Swift و iOS SDK. خلاف ذلك ، فإن المفهوم هو نفس مفهوم نظام Android الأساسي.

دعونا نكتب نفس التطبيق كما في الفصل السابق لمنصة iOS كذلك.

  • دعونا ننشئ تطبيقًا جديدًا في Android Studio ( macOS ) ، flutter_browser_ios_app

  • اتبع الخطوات من 2 إلى 6 كما في الفصل السابق.

  • ابدأ XCode وانقر فوق ملف → فتح

  • اختر مشروع xcode ضمن دليل iOS لمشروع flutter الخاص بنا.

  • افتح AppDelegate.m ضمن Runner → Runner path . يحتوي على الكود التالي -

#include "AppDelegate.h" 
#include "GeneratedPluginRegistrant.h" 
@implementation AppDelegate 

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

  • لقد أضفنا طريقة openBrowser لفتح المتصفح بعنوان URL محدد. يقبل حجة واحدة ، عنوان url.


- (void)openBrowser:(NSString *)urlString { 
   NSURL *url = [NSURL URLWithString:urlString]; 
   UIApplication *application = [UIApplication sharedApplication]; 
   [application openURL:url]; 
}
  • في طريقة didFinishLaunchingWithOptions ، ابحث عن وحدة التحكم واضبطها في متغير وحدة التحكم.


FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
  • في طريقة didFinishLaunchingWithOptions ، اضبط قناة المتصفح على أنها flutterapp.tutorialspoint.com/browse -



FlutterMethodChannel* browserChannel = [
   FlutterMethodChannel methodChannelWithName:
   @"flutterapp.tutorialspoint.com/browser" binaryMessenger:controller];
  • قم بإنشاء متغير weakself وقم بتعيين الفئة الحالية -


__weak typeof(self) weakSelf = self;
  • الآن ، قم بتنفيذ setMethodCallHandler. اتصل بـ openBrowser عن طريق مطابقة call.method. احصل على عنوان url عن طريق استدعاء call.arguments وتمريره أثناء استدعاء openBrowser.


[browserChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
   if ([@"openBrowser" isEqualToString:call.method]) { 
      NSString *url = call.arguments[@"url"];   
      [weakSelf openBrowser:url]; 
   } else { result(FlutterMethodNotImplemented); } 
}];
  • الكود الكامل Flutter  كما يلي -


#include "AppDelegate.h" 
#include "GeneratedPluginRegistrant.h" 
@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application 
   didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   
   // custom code starts 
   FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController; 
   FlutterMethodChannel* browserChannel = [
      FlutterMethodChannel methodChannelWithName:
      @"flutterapp.tutorialspoint.com /browser" binaryMessenger:controller]; 
   
   __weak typeof(self) weakSelf = self; 
   [browserChannel setMethodCallHandler:^(
      FlutterMethodCall* call, FlutterResult result) { 
      
      if ([@"openBrowser" isEqualToString:call.method]) { 
         NSString *url = call.arguments[@"url"];
         [weakSelf openBrowser:url]; 
      } else { result(FlutterMethodNotImplemented); } 
   }]; 
   // custom code ends 
   [GeneratedPluginRegistrant registerWithRegistry:self]; 
   
   // Override point for customization after application launch. 
   return [super application:application didFinishLaunchingWithOptions:launchOptions]; 
}
- (void)openBrowser:(NSString *)urlString { 
   NSURL *url = [NSURL URLWithString:urlString]; 
   UIApplication *application = [UIApplication sharedApplication]; 
   [application openURL:url]; 
} 
@end
  • افتح إعداد المشروع.

  • انتقل إلى Capabilities وقم بتمكين أوضاع Background Modes .

  • إضافة  * Background fetch و Remote Notification ** .

  • الآن ، قم بتشغيل التطبيق. إنه يعمل بشكل مشابه لإصدار Android ولكن سيتم فتح متصفح Safari بدلاً من Chrome