{"id":487,"date":"2011-08-02T16:07:41","date_gmt":"2011-08-02T08:07:41","guid":{"rendered":"http:\/\/xujiwei.com\/blog\/?p=487"},"modified":"2011-08-02T16:07:56","modified_gmt":"2011-08-02T08:07:56","slug":"auto-update-attr-in-ios-project","status":"publish","type":"post","link":"https:\/\/xujiwei.com\/blog\/2011\/08\/auto-update-attr-in-ios-project\/","title":{"rendered":"\u7ed9 iOS \u9879\u76ee\u6dfb\u52a0\u81ea\u52a8\u66f4\u65b0\u5c5e\u6027"},"content":{"rendered":"<p>\u5728 iOS \u9879\u76ee\u4e2d\uff0c\u6709\u4e9b\u65f6\u5019\u4e3a\u4e86\u65b9\u4fbf\u8ddf\u8e2a\u53d1\u5e03\u65f6\u7684\u7248\u672c\uff0c\u65b9\u4fbf\u8c03\u8bd5\uff0c\u6216\u8005\u4e3a\u4e86\u5c55\u793a\u7a0b\u5e8f\u7684\u7f16\u8bd1\u65e5\u671f\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728 Info.plist \u91cc\u9762\u6dfb\u52a0\u81ea\u5b9a\u4e49\u5c5e\u6027\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\uff0c\u4f46\u662f\u8fd9\u4e2a\u5de5\u4f5c\u662f\u4e00\u4e2a\u7eaf\u7cb9\u673a\u68b0\u7684\u91cd\u590d\u52b3\u52a8\uff0c\u6bcf\u6b21\u624b\u5de5\u53bb\u66f4\u65b0\u662f\u6bd4\u8f83\u9ebb\u70e6\u7684\u4e00\u4e2a\u4e8b\u60c5\u3002<\/p>\n<p>\u597d\u5728 Xcode \u9879\u76ee\u652f\u6301\u81ea\u5b9a\u4e49\u811a\u672c\u7684\u7f16\u8bd1\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u81ea\u5b9a\u4e49\u811a\u672c\u53bb\u66f4\u65b0 Info.plist\u3002<\/p>\n<p>\u5728 \/usr\/libexec \u76ee\u5f55\u4e0b\u9762\uff0c\u6709\u4e00\u4e2a\u5de5\u5177 PlistBuddy\uff0c\u5b83\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u4fee\u6539 plist \u6587\u4ef6\uff0c\u800c\u4e0d\u9700\u8981\u53bb\u7528 sed \u4e4b\u7c7b\u7684\u7f16\u8f91\u5de5\u5177\u6765\u4fee\u6539\u3002<\/p>\n<p>\u4e3a\u4e86\u5728\u4f7f\u7528 PlistBuddy \u7684\u65f6\u5019\u53ef\u4ee5\u76f4\u63a5\u7528 Set \u547d\u4ee4\u8bbe\u7f6e\u5c5e\u6027\uff0c\u6211\u4eec\u5148\u5728 iOS \u9879\u76ee\u7684 Info.plist \u91cc\u9762\u52a0\u4e00\u4e2a\u9700\u8981\u81ea\u52a8\u66f4\u65b0\u7684\u5c5e\u6027\uff0c\u4f8b\u5982 BUILD_DATE \u548c GIT_REVISION\uff0c\u7c7b\u578b\u9009\u62e9\u4e3a\u5b57\u7b26\u4e32\uff0c\u503c\u586b AUTO_GENERATED\u3002<\/p>\n<p>\u7136\u540e\u5728 iOS \u9879\u76ee\u7684 Target \u4e0a\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u7f16\u8bd1\u6b65\u9aa4 Run Script Build Phase\uff1a<\/p>\n<p><a href=\"http:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2011\/08\/add_script_step.png\" data-lbwps-width=\"873\" data-lbwps-height=\"283\" data-lbwps-srcsmall=\"https:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2011\/08\/add_script_step-300x97.png\"><img loading=\"lazy\" src=\"http:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2011\/08\/add_script_step-300x97.png\" alt=\"\" title=\"add_script_step\" width=\"300\" height=\"97\" class=\"alignnone size-medium wp-image-488\" srcset=\"https:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2011\/08\/add_script_step-300x97.png 300w, https:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2011\/08\/add_script_step-150x48.png 150w, https:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2011\/08\/add_script_step.png 873w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u4e0b\u9875\u5c31\u662f\u8981\u7f16\u5199\u811a\u672c\u4e86<\/p>\n<pre lang=\"bash\">\r\n# \u83b7\u53d6\u7f16\u8bd1\u7684\u65e5\u671f\r\nDATE=`date +%Y.%m.%d`\r\n\r\n# \u83b7\u53d6\u7f16\u8bd1\u65f6 Git \u5e93\u7684\u77ed\u7248\u672c\u53f7\r\nGIT_REVISION=`git rev-parse --short HEAD`\r\n\r\n# \u8bbe\u7f6e Info.plist \u4e2d\u76f8\u5173\u7684\u5c5e\u6027\r\n\/usr\/libexec\/PlistBuddy \"$TARGET_BUILD_DIR\/$INFOPLIST_PATH\" -c \"Set BUILD_DATE $DATE\"\r\n\/usr\/libexec\/PlistBuddy \"$TARGET_BUILD_DIR\/$INFOPLIST_PATH\" -c \"Set GIT_REVISION $GIT_REVISION\"\r\n\r\n# \u5c06 Info.plist \u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u683c\u5f0f\r\nplutil -convert binary1 \"$TARGET_BUILD_DIR\/$INFOPLIST_PATH\"\r\n<\/pre>\n<p>\u5982\u679c\u9700\u8981\u5728\u7a0b\u5e8f\u91cc\u83b7\u53d6\u8fd9\u4e9b\u5c5e\u6027\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre lang=\"c\">\r\nNSString *buildDate = [[NSBundle mainBundle] objectForInfoDictionaryKey:@\"BUILD_DATE\"];\r\nNSString *revision = [[NSBundle mainBundle] objectForInfoDictionaryKey:@\"GIT_REVISION\"];\r\n<\/pre>\n<p>--- EOF ---<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 iOS \u9879\u76ee\u4e2d\uff0c\u6709\u4e9b\u65f6\u5019\u4e3a\u4e86\u65b9\u4fbf\u8ddf\u8e2a\u53d1\u5e03\u65f6\u7684\u7248\u672c\uff0c\u65b9\u4fbf\u8c03\u8bd5\uff0c\u6216\u8005\u4e3a\u4e86\u5c55\u793a\u7a0b\u5e8f &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/xujiwei.com\/blog\/2011\/08\/auto-update-attr-in-ios-project\/\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,168],"tags":[178,148,154,177],"_links":{"self":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/487"}],"collection":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/comments?post=487"}],"version-history":[{"count":0,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/487\/revisions"}],"wp:attachment":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/media?parent=487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/categories?post=487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/tags?post=487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}