{"id":136,"date":"2022-11-25T15:12:21","date_gmt":"2022-11-25T07:12:21","guid":{"rendered":"https:\/\/app.applebyme.cn\/cloud\/wwwinfo\/136.html"},"modified":"2022-11-25T15:12:21","modified_gmt":"2022-11-25T07:12:21","slug":"ios%e5%bc%80%e5%8f%91%e4%bc%98%e5%8c%96app%e5%90%af%e5%8a%a8%e6%97%b6%e9%95%bf%ef%bc%8c%e6%9c%89%e7%9a%84app%e5%90%af%e5%8a%a8%e4%bc%9a%e9%bb%91%e5%b1%8f%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/app.applebyme.cn\/cloud\/wwwinfo\/136.html","title":{"rendered":"IOS\u5f00\u53d1\u4f18\u5316APP\u542f\u52a8\u65f6\u957f\uff0c\u6709\u7684app\u542f\u52a8\u4f1a\u9ed1\u5c4f\u4f18\u5316"},"content":{"rendered":"<p><strong>App\u542f\u52a8\u5927\u81f4\u6d41\u7a0b<\/strong><\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u6765\u8bf4\uff0c\u5b83\u7684\u52a0\u8f7d\u8fc7\u7a0b\u5206\u4e3a\u4e24\u5927\u90e8\u5206\uff1a<\/p>\n<p>1.pre-main \u6307\u7684\u662f\u64cd\u4f5c\u7cfb\u7edf\u5f00\u59cb\u6267\u884c\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u5b8c\u6210\u8fdb\u7a0b\u521b\u5efa\u3001\u6267\u884c\u6587\u4ef6\u52a0\u8f7d\u3001\u52a8\u6001\u94fe\u63a5\u3001\u73af\u5883\u914d\u7f6e<\/p>\n<p>2.main \u6307\u7684\u662f\u4ece\u52a0\u8f7dmain\u51fd\u6570\u5165\u53e3\u4ee5\u540e\uff0c\u5230<span class=\"wpcom_keyword_link\">app<\/span> delegate\u5b8c\u6210\u52a0\u8f7d\u56de\u8c03\u7684\u8fc7\u7a0b<\/p>\n<p><strong>\u64cd\u4f5c\u7cfb\u7edf\u52a0\u8f7dApp\u53ef\u6267\u884c\u6587\u4ef6<\/strong><\/p>\n<p>\u64cd\u4f5c\u7cfb\u7edf\u52a0\u8f7d\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u901a\u8fc7fork(\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b)\u6307\u4ee4\u5728\u65b0\u7684\u7a7a\u95f4\u5185\u6765\u6267\u884c\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u52a0\u8f7d\u4f9d\u8d56\u7684\u53ef\u6267\u884c\u6587\u4ef6(mach-o)\u6587\u4ef6\uff0c\u5b9a\u4f4d\u5176\u5185\u90e8\u4e0e\u5916\u90e8\u6307\u9488\u5f15\u7528\uff0c\u4f8b\u5982\u5b57\u7b26\u4e32\u4e0e\u51fd\u6570\uff0c\u6267\u884c\u58f0\u660e\u4e3aattribute((constructor))\u7684C\u51fd\u6570\uff0c\u52a0\u8f7d\u6269\u5c55(Category)\u4e2d\u7684\u65b9\u6cd5\uff0cC++\u9759\u6001\u5bf9\u8c61\u52a0\u8f7d\uff0c\u8c03\u7528ObjC\u7684+load\u51fd\u6570<\/p>\n<p>\u57fa\u672c\u6d41\u7a0b<strong>\uff1a<\/strong><\/p>\n<p>App \u5f00\u59cb\u542f\u52a8\u540e\uff0c\u7cfb\u7edf\u9996\u5148\u52a0\u8f7d\u53ef\u6267\u884c\u6587\u4ef6(\u81ea\u8eab App \u7684\u6240\u6709 .o \u6587\u4ef6\u7684\u96c6\u5408)\uff0c\u7136\u540e\u52a0\u8f7d\u52a8\u6001\u94fe\u63a5\u5668 dyld\uff0cdyld \u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u6765\u52a0\u8f7d\u52a8\u6001\u94fe\u63a5\u5e93\u7684\u5e93\u3002 \u6267\u884c\u4ece dyld \u5f00\u59cb\uff0cdyld \u4ece\u53ef\u6267\u884c\u6587\u4ef6\u7684\u4f9d\u8d56\u5f00\u59cb\uff0c\u9012\u5f52\u52a0\u8f7d\u6240\u6709\u7684\u4f9d\u8d56\u52a8\u6001\u94fe\u63a5\u5e93\u3002<\/p>\n<p>\u52a8\u6001\u94fe\u63a5\u5e93\u5305\u62ec\uff1aiOS \u4e2d\u7528\u5230\u7684\u6240\u6709\u7cfb\u7edf framework\uff0c\u52a0\u8f7d OC runtime \u65b9\u6cd5\u7684 libobjc\uff0c\u7cfb\u7edf\u7ea7\u522b\u7684 libSystem\uff0c\u4f8b\u5982 libdispatch(GCD) \u548c libsystem_blocks (Block)\u3002<\/p>\n<p><strong>\u3000ObjC Runtime<\/strong><\/p>\n<p>dyld\u7684\u52a0\u8f7d\u8fc7\u7a0b\u4f1a\u521d\u59cb\u5316Runtime\u7cfb\u7edf\uff0c\u5728\u6b64\u9636\u6bb5\uff0c\u6709\u76f8\u5f53\u591a\u7684\u4f18\u5316\u5de5\u4f5c\u53ef\u4ee5\u505a<\/p>\n<p>\u8fd9\u8fc7\u7a0b\u5305\u62ec\uff1a<\/p>\n<p>1.\u6240\u6709\u7c7b\u578b\u7684\u5b9a\u4e49\u548c\u6ce8\u518c\uff0cObjective-C\u7684\u7c7b\u4e0d\u662f\u7f16\u8bd1\u5668\u51b3\u5b9a\u7684\uff0c\u662f\u8fd0\u884c\u65f6\u52a8\u6001\u8f7d\u5165\u5230\u5168\u5c40\u8868\u4e2d\u7684<\/p>\n<p>2.\u975e\u8106\u5f31\u7684ivars\u53d8\u91cf\u62b5\u6d88\u66f4\u65b0\uff0c\u4fee\u6539\u5b9e\u4f8b\u53d8\u91cf\u7684\u5185\u5b58\u5730\u5740\u504f\u79fb\u95ee\u9898<\/p>\n<p>3.\u5206\u7c7b\u66ff\u6362\u5e76\u6dfb\u52a0\u5230\u65b9\u6cd5\u5217\u8868\u4e2d\uff0c\u5c06\u5206\u7c7b\u4e2d\u7684\u65b9\u6cd5\u52a0\u8f7d\u5230\u65b9\u6cd5\u5217\u8868\u4e2d<\/p>\n<p>4.\u786e\u8ba4\u9009\u62e9\u5668\u5168\u5c40\u552f\u4e00<\/p>\n<p><strong>Initializers \u9636\u6bb5<\/strong><\/p>\n<p>\u5728Runtime\u7cfb\u7edf\u52a0\u8f7d\u4ee5\u540e\uff0c\u5f00\u59cb\u8fdb\u884c\u521d\u59cb\u5316<\/p>\n<p>1.Objc\u7684+load()\u51fd\u6570<\/p>\n<p>2.C++\u7684\u6784\u9020\u51fd\u6570\u5c5e\u6027\u51fd\u6570 \u5f62\u5982attribute((constructor)) void DoSomeInitializationWork()<\/p>\n<p><strong><\/strong>3.\u975e\u57fa\u672c\u7c7b\u578b\u7684C++\u9759\u6001\u5168\u5c40\u53d8\u91cf\u7684\u521b\u5efa(\u901a\u5e38\u662f\u7c7b\u6216\u7ed3\u6784\u4f53)(non-trivial initializer) \u6bd4\u5982\u4e00\u4e2a\u5168\u5c40\u9759\u6001\u7ed3\u6784\u4f53\u7684\u6784\u5efa\uff0c\u5982\u679c\u5728\u6784\u9020\u51fd\u6570\u4e2d\u6709\u7e41\u91cd\u7684\u5de5\u4f5c\uff0c\u90a3\u4e48\u4f1a\u62d6\u6162\u542f\u52a8\u901f\u5ea6<\/p>\n<p><strong>pre-main\u9636\u6bb5\u5206\u6790<\/strong><\/p>\n<p>\u4ece\u4e0a\u9762\u53ef\u4ee5\u5f97\u51fa\u4ee5\u4e0b\u51e0\u4e2a\u7ed3\u8bba\uff0c\u5f71\u54cd\u8be5\u9636\u6bb5\u542f\u52a8\u65f6\u95f4\u7684\u56e0\u7d20\u5982\u4e0b\uff1a<\/p>\n<p>1.Mach-O\u53ef\u6267\u884c\u6587\u4ef6\u7684\u52a0\u8f7d\u548c\u5185\u5b58\u91cd\u65b0\u5206\u914d\u89c4\u5212\uff0c\u5bf9\u4e8e\u5176segment\u548csection\u8fdb\u884c\u865a\u62df\u5185\u5b58\u7684\u5206\u9875\u7ba1\u7406\u7684\u8c03\u5ea6<\/p>\n<p>2.dyld\u52a8\u6001\u94fe\u63a5\u5185\u5b58\u4e2d\u7684\u516c\u5171\u955c\u50cf\uff0c\u5728\u8fd0\u884c\u65f6\u8fdb\u884c\u68c0\u67e5\u5171\u4eab\u6570\u636e\u548c\u94fe\u63a5\u8c03\u7528<\/p>\n<p>3.Runtime\u7684\u521d\u59cb\u5316\uff0c\u5305\u62ecclass\u6ce8\u518c\u3001category\u52a0\u8f7d\u3001\u53d8\u91cf\u5bf9\u9f50\u7b49<\/p>\n<p>4.C++\u9759\u6001\u5bf9\u8c61\u548c\u5168\u5c40\u53d8\u91cf\u7684\u52a0\u8f7d<\/p>\n<p>5.ObjeC\u6240\u6709load\u51fd\u6570\u7684\u8c03\u7528\u52a0\u8f7d<\/p>\n<p>\u4f18\u5316\u63aa\u65bd\uff1a<\/p>\n<p>1.\u51cf\u5c11ObjC\u7684\u7c7b\u81a8\u80c0\u95ee\u9898\uff0c\u6e05\u7406\u6ca1\u6709\u4f7f\u7528\u7684\u7c7b\uff0c\u5408\u5e76\u677e\u6563\u65e0\u7528\u7684\u7c7b<\/p>\n<p>2.\u51cf\u5c11\u9759\u6001\u53d8\u91cf\u7684\u58f0\u660e\u548c\u521d\u59cb\u5316\u7684\u5206\u79bb\uff0c\u51cf\u5c11\u9759\u6001\u53d8\u91cf\u7684\u4f7f\u7528<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/03\/20220322075009627.png\" alt=\"IOS\u5f00\u53d1\u4f18\u5316APP\u542f\u52a8\u65f6\u957f\uff0c\u6709\u7684app\u542f\u52a8\u4f1a\u9ed1\u5c4f\u4f18\u5316\"><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/03\/20220322075009627.png\" alt=\"IOS\u5f00\u53d1\u4f18\u5316APP\u542f\u52a8\u65f6\u957f\uff0c\u6709\u7684app\u542f\u52a8\u4f1a\u9ed1\u5c4f\u4f18\u5316\"><\/figure>\n<p>3.\u51cf\u5c11\u7b26\u53f7\u8868\u7684\u5bfc\u51fa<\/p>\n<p>\u901a\u8fc7\u8bbe\u7f6e-exported_symbols_list\u6216-unex<a href=\"https:\/\/app.applebyme.cn\/shengcheng-103.html\">\u751f\u6210web app<\/a>ported_symbols_lis\u6765\u9650\u5236\u7b26\u53f7\u8868\u7684\u5bfc\u51fa\uff0c\u4ece\u800c\u51cf\u5c11dyld\u7684\u5de5\u4f5c\u91cf<\/p>\n<p>4.\u53bb\u9664\u6ca1\u6709\u4f7f\u7528\u7684\u52a8\u6001\u5e93\u4f9d\u8d56\uff0c\u660e\u786e\u6240\u4f9d\u8d56\u7684frameworks\u662frequire\u8fd8\u662foptional\uff0coptional\u4f1a\u52a8\u6001\u8fdb\u884c\u989d\u5916\u68c0\u67e5<\/p>\n<p>5.\u5220\u9664\u6ca1\u6709\u7528\u7684\u65b9\u6cd5<\/p>\n<p>6.\u51cf\u5c11+load\u51fd\u6570\u7684\u5b9e\u73b0\uff0c\u5e76\u51cf\u5c11\u5728\u5176\u4e2d\u64cd\u4f5c\u7684\u903b\u8f91<\/p>\n<p>7.\u5bf9\u67d0\u4e9b\u7ecf\u5e38\u8c03\u7528\u7684\u4ee3\u7801\u8fdb\u884c\u4e8c\u8fdb\u5236\u5316\uff0c\u751f\u6210\u9759\u6001\u5e93\uff0c\u591a\u4f7f\u7528\u9759\u6001\u5e93\u4ee3\u66ff\u52a8\u6001\u5e93\uff0c\u5c06\u591a\u4e2a\u9759\u6001\u5e93\u6846\u67b6\uff0c\u96c6\u4e2d\u5236\u4f5c\u6210\u9759\u6001framework\uff0c\u4ece\u800c\u80fd\u591f\u51cf\u5c11dyld\u7684\u94fe\u63a5\u5de5\u4f5c<\/p>\n<p><strong><a href=\"https:\/\/app.applebyme.cn\/shengcheng-52.html\">\u7f51\u5740app\u751f\u6210\u8f6f\u4ef6<\/a>main\u9636\u6bb5<\/strong><\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/03\/20220322075010836.png\" alt=\"IOS\u5f00\u53d1\u4f18\u5316APP\u542f\u52a8\u65f6\u957f\uff0c\u6709\u7684app\u542f\u52a8\u4f1a\u9ed1\u5c4f\u4f18\u5316\"><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/03\/20220322075010836.png\" alt=\"IOS\u5f00\u53d1\u4f18\u5316APP\u542f\u52a8\u65f6\u957f\uff0c\u6709\u7684app\u542f\u52a8\u4f1a\u9ed1\u5c4f\u4f18\u5316\"><\/figure>\n<p>\u4ece\u4e0a\u56fe\u53ef\u4ee5\u5f97\u5230\uff0c\u5f71\u54cdmain\u9636\u6bb5\u7684\u542f\u52a8\u65f6\u95f4\u56e0\u7d20\u662f\uff1a<\/p>\n<p>1.AppDelegate\u4ee3\u7406\u7684\u52a0\u8f7d\u751f\u547d\u5468\u671f\u56de\u8c03<\/p>\n<p>2.Application Window\u7684\u5e03\u5c40\u3001\u7ed8\u5236\u548c\u52a0\u8f7d<\/p>\n<p>3.RootViewController\u7684\u52a0\u8f7d<\/p>\n<p>\u4f18\u5316\u70b9\uff1a<\/p>\n<p>1.\u538b\u7f29\u548c\u51cf\u5c0f\u542f\u52a8\u56fe\u7247<\/p>\n<p>2.\u5c3d\u91cf\u4e0d\u4f7f\u7528storyboard\u6216\u8005\u662fnib\u6765\u5e03\u5c40rootViewController<\/p>\n<p>3.\u5728didFinishLaunchingWithOptions\u9636\u6bb5\uff0c\u5c3d\u53ef\u80fd\u51cf\u5c11\u963b\u585e\u4ee3\u7801\u7684\u6267\u884c\uff0c\u53ef\u4ee5\u5229\u7528\u591a\u7ebf\u7a0b\u8fdb\u884c\u52a0\u8f7d\u903b\u8f91\u7684\u5904\u7406\uff0c\u6ce8\u610f\u591a\u7ebf\u7a0b\u5bf9\u4e3b\u7ebf\u7a0b\u540c\u6b65\u963b\u585e\u53ef\u80fd\u9020\u6210\u7684\u9ed1\u5c4f\u95ee\u9898<\/p>\n<p>4.\u5c06\u975e\u540c\u6b65\u9700\u6c42\u7684\u521d\u59cb\u5316\u903b\u8f91\u8fdb\u884c\u5f02\u6b65\u52a0\u8f7d<\/p>\n<div class=\"entry-copyright\">\n<p>\u7f16\u8f91\uff1a\u5a1c\u5a1c\uff0c\u5982\u82e5\u8f6c\u8f7d\uff0c\u8bf7\u6ce8\u660e\u51fa\u5904\uff1ahttps:\/\/www.yimenapp.com\/kb-yimen\/1210\/<\/p>\n<p>\u90e8\u5206\u5185\u5bb9\u6765\u81ea\u7f51\u7edc\u6295\u7a3f\uff0c\u5982\u6709\u4fb5\u6743\u8054\u7cfb\u7acb\u5220<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5728didFinishLaunchingWithOptions\u9636\u6bb5\uff0c\u5c3d\u53ef\u80fd\u51cf\u5c11\u963b\u585e\u4ee3\u7801\u7684\u6267\u884c\uff0c\u53ef\u4ee5\u5229\u7528\u591a\u7ebf\u7a0b\u8fdb\u884c\u52a0\u8f7d\u903b\u8f91\u7684\u5904\u7406\uff0c\u6ce8\u610f\u591a\u7ebf\u7a0b\u5bf9\u4e3b\u7ebf\u7a0b\u540c\u6b65\u963b\u585e\u53ef\u80fd\u9020\u6210\u7684\u9ed1\u5c4f\u95ee\u9898<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[362,275,284],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-wwwinfo","tag-app","tag-ios"],"_links":{"self":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":0,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"wp:attachment":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}