2017-11-13 6 views
-4

これはどのように迅速に変換されますか?最低限必要なのは、電子メールメッセージに追加されたアプリ名、アプリのバージョン、ロケールまたは国です。メッセージのボディと付け加え運を持っていないのに電子メールメッセージ本文にアプリとデバイスの情報を表示する - スウィフト

NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]; 
UIDevice *currentDevice = [UIDevice currentDevice]; 
NSString *model = [currentDevice model]; 
NSString *systemVersion = [currentDevice systemVersion]; 
NSArray *languageArray = [NSLocale preferredLanguages]; 
NSString *language = [languageArray objectAtIndex:0]; 
NSLocale *locale = [NSLocale currentLocale]; 
NSString *country = [locale localeIdentifier]; 
NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; 
NSString *emailBody = [NSString stringWithFormat:@"\n\n\n\n\n\n\n\n\nApp Name: %@ \nModel: %@ \nSystem Version: %@ \nLanguage: %@ \nCountry: %@ \nApp Version: %@", appName, model, systemVersion, language, country, appVersion]; 

は、これまでのところ私は

let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String 

を見つけました。

これはこれまで私が行ってきたことです。

@IBAction func sendMail(_ sender: AnyObject) { 

    let recipients = ["[email protected]"] 
    let title = "App feedback" 
    let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String 


    let message = "" 

    let mc: MFMailComposeViewController = MFMailComposeViewController() 

    mc.mailComposeDelegate = self 

    mc.setToRecipients(recipients) 
    mc.setSubject(title) 
    mc.setMessageBody(message, isHTML: false) 

    self.present(mc, animated: true, completion: nil) 
+0

あなたはコードを変換していません。あなたの 'message'は空の文字列です。すべてのコードを変換し、次に成功しない場合は質問を投稿してください。 – rckoenes

+0

はい、私はそれを追加する方法はわかりませんがわかります。プラス私はコードを変換するための助けを求めています。 – Enquinn

+0

あなたはObjective-Cを素早く1行に翻訳しておらず、 'stringWithFormat:'がメッセージを作成するのに使われている穴の部分がありません。あなたは疑問に思っています。私はこのコードを持っていますので、Swift版を作成してください。この種の質問はぶつかり、下降する。すべてのObj-cラインをSwiftに変換します。 – rckoenes

答えて

0

あなたは正しい経路にいる。私はちょうど例では、あなたのappversionをハードコード

let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String 
let appVersion = "5" 

var message = "App name: \(appName)\n" 
message += "Version: \(appVersion)" 

:あなたはスウィフト4にしている場合は、複数行文字列リテラルを使用し、そのようなあなたのメッセージをフォーマットすることができます:

let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String 
let appVersion = "5" 


let message = """ 
App name: \(appName) 
Version: \(appVersion) 
""" 

スウィフト3バージョンあなたの変数をあなたのメッセージに挿入する方法を具体的に尋ねてきたからです。希望が役立ちます。

+0

私はスイフト3にいるが、それは私の後ろにあるもので、それは私にとってはうまくいかないようだ。 – Enquinn

+0

Swift 3のバージョンを追加しました。 – Terje

関連する問題