2016-04-12 18 views
1

ここは新しいです。誰かが私を助けることを願っています!.plistファイルの配列内に文字列を書き込む方法

私はAppList(Ryan Petrich)を追加して動作させているので、すべてのアプリケーションとスイッチオン/オフで、各アプリケーションのlinkcellを好みの状態でバンドルしています。

一部をオンにすると、<key>ALvalue-com.some.app</key>と値<true/>が環境設定.plistに保存されます。

私はこのようになり、「キー」「BOOLVALUE」の構造を変更する方法を把握しようとしている:

AL-hd.plistファイル

<dict> 
    <key>AL-hd</key> 
    <array> 
     <string>com.apple.AppStore</string> 
     <string>com.apple.gamecenter</string> 
     <string>com.apple.stocks</string> 
    </array> 
</dict> 
</plist> 

の代わりに、この

<dict> 
    <key>ALvalue-com.apple.AppStore</key> 
    <true/> 
    <key>ALvalue-com.apple.gamecenter</key> 
    <true/> 
    <key>ALvalue-com.apple.stocks</key> 
    <true/> 
</dict> 
</plist> 

これは、設定ファイルAL-hd.plistを節約し、私のAPPLISTのの.plistです:

<dict> 
     <key>cell</key> 
     <string>PSLinkCell</string> 
     <key>bundle</key> 
     <string>AppList</string> 
     <key>isController</key> 
     <string>1</string> 
     <key>label</key> 
     <string>Show apps</string> 
     <key>icon</key> 
     <string>Favorites.png</string> 
     <key>ALAllowsSelection</key> 
     <string>1</string> 
     <key>ALChangeNotification</key> 
     <string>com.your.companyChanged</string> 
     <key>ALSectionDescriptors</key> 
     <array> 
      <dict> 
       <key>footer-title</key> 
       <string>Check what apps you want to show up</string> 
       <key>items</key> 
       <array/> 
      </dict> 
      <dict> 
       <key>cell-class-name</key> 
       <string>ALCheckCell</string> 
       <key>icon-size</key> 
       <string>29</string> 
       <key>suppress-hidden-apps</key> 
       <string>1</string> 
       <key>title</key> 
       <string>All Applications</string> 
      </dict> 
     </array> 
     <key>ALSettingsKeyPrefix</key> 
     <string>ALvalue-</string> 
     <key>ALSettingsPath</key> 
     <string>/var/mobile/Library/Preferences/AL-hd.plist</string> 
    </dict> 

私はたくさんのものを探し、何百ものものを試します。

ありがとうございます!

私が試した1つのことは、2番目の.plistを作成し、後でそのキーをコピーして2番目のファイルに文字列のように貼り付けることでした。そして、(運を持つ).mmファイルにこのアクションで好みのバンドルにボタンを追加するには:私は好みバンドルの.plistを使用するか、または第二いずれかを使用して、コピーした場合、私のために

- (void)save 
{ 
    NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier]; 

    // Either this or whatever works from link after this 
    NSString *prefPath = @"/User/Library/Preferences/com.your.company.plist"; 
    NSString *showPath = @"/User/Library/Preferences/AL-hd.plist"; 
    NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:prefPath];  
    NSMutableArray *show = [[NSMutableArray alloc] initWithContentsOfFile:showPath];  
    if ([[plistDict objectForKey:bundleID] boolValue]) { 
      [Show addObject:bundleID]; 
    } 
} 

は関係ありません私が必要とするような行。

+0

あなたの問題が何であるかは不明です。コードを表示し、必要なものとは異なる仕組みを説明する必要があります。次に、誰かがあなたを助けるかもしれません。質問自体を編集し、コメントに資料を追加しないでください。 – CRD

+0

2つのplistファイルを1つにマージしたいですか? – phi

+0

いいえ、私はより明確に答えを編集しています...私の英語で申し訳ありません! – Olivier

答えて

0

このようにします。

  1. 新しい.plistファイルを作成し、プロパティリストとして開きます。

  2. [+]をクリックすると、情報プロパティリスト内に新しいプロパティが作成されます。

  3. プロパティに名前を付けます。たとえば、「テキスト」に「アレイ」と入力します。

  4. 上記の作成された配列内に新しい項目を追加し、各項目にテキストを入力します。

  5. あなたのビューコントローラクラスで、これを行う必要があります。

    //ViewController.h 
    
        @property (nonatomic,strong)NSArray *plistDataArr; 
    
        //ViewController.m 
    
    
    -(NSArray*) plistDataArr 
        { 
        if(! _plistDataArr) 
        { 
         NSString *filePath = [[NSBundle mainBundle]pathForResource:@"YOUR Plist file name" ofType:@"plist"]; 
        _plistDataArr = [NSArray arrayWithContentsOfFile:filePath]; 
        } 
        return _plistDataArr; 
    
        } 
    
        //viewDidLoad 
    
        NSMutableArray *tempArr=[NSMutableArray arrayWithArray:self. _plistDataArr]; 
    
+0

ありがとう!しかし、私は.mと.hファイルを持っていません。唯一.mm。私はそれらのファイルを.mmに変更する方法はまだ分かりません。これは私に起こっている、私が設立したすべての例はあなたのものと同じです... – Olivier

+0

Plz upvote my answer、他の人も利益を得ることができます。 –

関連する問題