0%

App根据Build状态显示不同图片

之前用 fastlane 的插件 badge 做了类似的功能,虽然可以使用,但是需要安装 homebrew 环境。
尤其是 imagemagick 包关联的依赖太多,本地还好,放到 circle ci 上每次跑都要安装那肯定不行,build 时间太久,使用了 cache 一段时间之后,出现了错误,同事解决了半天也没搞定,就找到了这个方法,简直太棒了。

以下是原文大概翻译,供自己记录看看。

原文随译

引言

You’ve got an app in the App Store. You want to keep iterating upon it. You also want to test it in the wild before releasing updates to your userbase. Sound familiar?
正式版和测试版都在手机上时候遇到一个问题?

If you’ve done this before, you know you’ll want to have a beta version of your app, and you want to run it alongside your “App Store” and development builds. But, unless you take some time to set things up, your homescreen will start looking like this:(这里有一张图片,显示两个一样的图标并列在一起)
如果没有适当处理的话,两个app放在一起根本无法区别彼此。

1

Which one’s which?

Turns out, this is a pretty simple problem to solve in Xcode
看来xcode可以解决这个问题。(2014年的文章了,到现在才了解也是服了)

处理方法

先复制一个 beta configure 出来 (Make a beta)

First, if you haven’t already set up a Beta build, you should do that now.

In Xcode, click on your project, and click on your project on the top of the left pane. Be sure the project is selected in the top left — not your Target.

On the Info tab, click the “+” Sign under “Configurations” and select “Duplicate ‘Release’ Configruation”

Name this configuration “Beta”
反正一顿乱操作,就是配置了个新的 configure 文件,看图。

2

改变app名字, Give your apps a name

While you’re in your project settings, select your Target from the left sidebar and go to the “Build Settings” tab.

In the “Packaging” section of your Build Settings, expand the “Product Name” field. (If you can’t find it, just search in the top right bar)

In each of the configurations, give your app a new name.

We found it useful to keep Debug and Release named “Circle” and to only name the “Beta” build, since Beta would be used by external people (and we can have more fun with our “Debug” icon to distinguish it).
这里设置显示相应的 app 名字,图不一样当然名字也可以自定义啦。

3

添加自定义的字符串

这个步骤可以省略,我省略了,因为只有一个beta图标需要设置,如果多个,可以操作这个步骤

So far so good. But now, every time we run our Dev or Beta build, it overwrites our Release build from the App Store. Not ideal for field testing.

The next step is to make it so we can run these apps side-by-side.

On the top bar, click the + sign and “Add User-Defined Setting”

4

Name it BUNDLE_ID_SUFFIX (or something similar — you’ll need to re-use this name later)

Open the dropdown and give the following values for each configuration, leaving the “Release” value blank:

5

Now open up Info.plist and locate the “Bundle Identifier” setting. Edit it and append ${BUNDLE_ID_SUFFIX} to your existing bundle id. For example, if your bundle id is com.crab.awesome, you’d change it to com.crab.awesome${BUNDLE_ID_SUFFIX}

Notice how we’re using the BUNDLE_ID_SUFFIX you just created? This makes it so you’ll have 3 bundle identifiers automatically — com.crab.awesome for Release, com.crab.awesome.dev for Debug, and com.crab.awesome.beta for Beta.

为不同的configure指定不同的icon

OK, now it’s time for the fun: setting a unique App Icon for each of your builds.

Go back to your project settings, select your Target, and choose “Build Settings” Under “Asset Catalog Compiler — Options”, find the “Asset Catalog App Icon Set Name” setting.

Don’t expand this one, just set the value to be AppIcon${BUNDLE_ID_SUFFIX}.

6

Again, notice how we’re using BUNDLE_ID_SUFFIX here. This makes it so the build process will look for an app icon named AppIcon.beta during Beta builds, AppIcon.dev during Debug builds and plain-old AppIcon during Release builds.

NOTE: You may also see the “Asset Catalog Launch Image Set Name” below this setting. You could also do the same thing here if you wanted different launch images per build type.

That was easy. But we’re not done just yet. There’s one more step: You have to add the icons to your app.
当然也可以改变不同的launch image。

添加多个AppIcon图片资源

Open your Images.xcassets file. Click the + on the bottom left, and select “New App Icon”. Name it AppIcon.dev. Do it again for AppIcon.beta (notice a theme here?)

7

Now fill these in with icons (we like using the App Icon Template from PixelResort).

Most importantly, be sure to have fun with the development one.

8

结果很美好

And voila — you now have different apps running along side eachother with different icons.

9

参考

Different App Icons for your iOS Beta, Dev, and Release builds