apk\u8868\u5355\u5f00\u53d1<\/a> \u4e2d\u914d\u7f6e Flutter \u5f15\u64ce\u7684\u8def\u5f84\uff0c\u9009\u62e9 Build Settings -> Framework Search Paths\uff0c\u6dfb\u52a0 Flutter \u5f15\u64ce\u7684\u8def\u5f84\uff0c\u4f8b\u5982\uff1a<\/p>\n“`<\/p>\n
$(SRCROOT)\/..\/flutter\/bin\/cache\/artifacts\/engine\/ios<\/p>\n
“`<\/p>\n
4. \u5728 AppDelegate.swift \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff0c\u7528\u4e8e\u52a0\u8f7d Flutter \u5f15\u64ce\uff1a<\/p>\n
“`swift<\/p>\n
import Flutter<\/p>\n
…<\/p>\n
let flutterEngine = FlutterEngine(name: “my_flutter_engine”)<\/p>\n
flutterEngine.run()<\/p>\n
“`<\/p>\n
### 2. \u7f16\u8bd1 Flutter \u4ee3\u7801<\/p>\n
\u7f16\u8bd1 Flutter \u4ee3\u7801\u9700\u8981\u8fdb\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n
1. \u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528 Flutter \u547d\u4ee4\u7f16\u8bd1 Flutter \u4ee3\u7801\uff0c\u4f8b\u5982\uff1a<\/p>\n
“`<\/p>\n
flutter build aot –release –output-dir=\/path\/to\/output\/dir<\/p>\n
“`<\/p>\n
2. \u5728 Xcode \u4e2d\u9009\u62e9 iOS \u5e94\u7528\u7684\u5de5\u7a0b\u6587\u4ef6\uff0c\u9009\u62e9 Build Phases -> Link Binary With Libraries\uff0c\u6dfb\u52a0 Flutter \u7684\u52a8\u6001\u5e93\uff0c\u4f8b\u5982\uff1a<\/p>\n
“`<\/p>\n
\/path\/to\/output\/dir\/App.framework<\/p>\n
“`<\/p>\n
3. \u5728 Xcode \u4e2d\u9009\u62e9 iOS \u5e94\u7528\u7684\u5de5\u7a0b\u6587\u4ef6\uff0c\u9009\u62e9 Build Phases -> Copy Files\uff0c\u6dfb\u52a0 Flutter \u7684\u52a8\u6001\u5e93\uff0c\u8bbe\u7f6e Destination \u4e3a Frameworks\uff0c\u4f8b\u5982\uff1a<\/p>\n
“`<\/p>\n
\/path\/to\/output\/dir\/App.framework<\/p>\n
“`<\/p>\n
### 3. \u8c03\u7528 Flutter \u4ee3\u7801<\/p>\n
\u8c03\u7528 Flutter \u4ee3\u7801\u9700\u8981\u8fdb\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n
1. \u5728\u539f\u751f iOS \u89c6\u56fe\u4e2d\u521b\u5efa FlutterViewController\uff0c\u4f8b\u5982\uff1a<\/p>\n
“`swift<\/p>\n
let flutterViewController = FlutterViewContr<\/p>\n
<\/figure>\n<\/p>\noller(engine: flutterEngine, nibName: nil, bundle: nil)<\/p>\n
“`<\/p>\n
2. \u5728\u539f\u751f iOS \u89c6\u56fe\u4e2d\u6dfb\u52a0 Flutter \u89c6\u56fe\uff0c\u4f8b\u5982\uff1a<\/p>\n
“`swift<\/p>\n
addChild(flutterViewController)<\/p>\n
flutterViewController.view.frame = view.bounds<\/p>\n
view.addSubview(flutterViewController.view)<\/p>\n
“`<\/p>\n
3. \u5728 Flutter \u4ee3\u7801\u4e2d\u4f7f\u7528 Platform Channel \u4e0e\u539f\u751f iOS \u4ee3\u7801\u8fdb\u884c\u901a\u4fe1\uff0c\u4f8b\u5982\uff1a<\/p>\n
“`dart<\/p>\n
import ‘package:flutter\/services.dart’;<\/p>\n
…<\/p>\n
final platform = MethodChannel(‘com.example.myapp\/mychannel’);<\/p>\n
…<\/p>\n
platform.invokeMethod(‘myMethod’, {‘arg1’: ‘value1’, ‘arg2’: ‘value2’});<\/p>\n
“`<\/p>\n
\u4ee5\u4e0a\u5c31\u662f iOS \u6df7\u5408 Flutter \u6253\u5305\u7684\u8be6\u7ec6\u6b65\u9aa4\u3002\u901a\u8fc7\u5c06 Flutter \u4ee3\u7801\u4e0e\u539f\u751f iOS \u4ee3\u7801\u6df7\u5408\u5728\u4e00\u8d77\uff0c\u53ef\u4ee5\u5b9e\u73b0\u66f4\u52a0\u4e30\u5bcc\u548c\u590d\u6742\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
iOS \u6df7\u5408 Flutter \u6253\u5305\u662f\u5c06 Flutter \u4ee3\u7801\u4e0e\u539f\u751f iOS \u4ee3\u7801\u6df7\u5408\u5728\u4e00\u8d77\u8fdb\u884c\u6253\u5305\uff0c\u4f7f\u5f97 Flutter \u4ee3\u7801\u53ef\u4ee5\u5728 iOS \u5e94\u7528\u4e2d\u8fd0\u884c\u3002\u672c\u6587\u5c06\u4ecb\u7ecd iOS \u6df7\u5408 Flutter \u6253<\/p>\n","protected":false},"author":24,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[25210,25209,38,5945,207],"topic":[],"class_list":["post-26227","post","type-post","status-publish","format-standard","hentry","category-kaifaapp","tag-h5app","tag-ipa","tag-38","tag-5945","tag-207"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/26227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=26227"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/26227\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=26227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=26227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=26227"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=26227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}