1

iOS アプリケーションで html の形式で About を表示しています。About.html もアプリケーションと一緒にバンドルされています。
バージョンを変更するたびにHTMLを手動で編集する必要がないように、About htmlページにアプリケーションのバージョンを自動的に表示したいと考えています。
現在、私がやっていることは次のとおりです:
私は html を次のように作成して<b>Version %@</b>
います

    NSString* aboutFilePath = [[NSBundle mainBundle] pathForResource:@"About" ofType:@"html"];
    NSString* htmlStr = [NSString alloc] initWithContentsOfFile:aboutFilePath encoding:NSUTF8StringEncoding error:nil];
    NSString* formattedStr = [NSString stringWithFormat:htmlStr, [self appNameAndVersionNumberDisplayString];
   [self.webView loadHTMLString:formattedStr baseURL:nil];

- (NSString *)appNameAndVersionNumberDisplayString {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    NSString *majorVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSString *minorVersion = [infoDictionary objectForKey:@"CFBundleVersion"];

    return [NSString stringWithFormat:@"%@, Version %@ (%@)", 
                appDisplayName, majorVersion, minorVersion];
}

それを行うのは良い方法ですか、それともそれを達成するためのより良い方法はありますか?

4

2 に答える 2

0

それで大丈夫です。将来テキストをローカライズする場合は、テキスト内のパラメーターの順序が変更される可能性があるため、SUB_VERSION置き換えられる識別子としてより似たものを使用し、文字列置換メソッド (フォーマット メソッドの代わりに) を使用する方がよいでしょう。

于 2013-08-05T06:37:02.153 に答える
0

あなたはそれをほぼ完璧な方法でやっています。アプローチを進めても問題ありません。

于 2013-08-05T07:04:09.837 に答える