How do you write to a plist with a non specific path?

Discussion in 'iOS Development' started by ipodtouchmaster05, Jul 1, 2008.

  1. ipodtouchmaster05

    ipodtouchmaster05 Well-Known Member

    Joined:
    Sep 30, 2007
    Messages:
    1,787
    Likes Received:
    41
    Device:
    iPhone 5 (Black)
    Kind of hard to explain but I have an app I am working on that shows all the applications you have installed, then when you click on one you ahve the option to lock or unlock tht application. Now there are a few things that happen when you click lock basically it copy's another application into that app folder then it is supposed to change the Info.plist's CFBundleExecutable to the name of that temp. app placed in there. Here is where my problem is, I cant seem to get this to change the plist so I am posting part of my source code, any help would be great thanks.

    Code:
    - (void)tableRowSelected:(NSNotification *)notification {
    chosenFile = [ filenames objectAtIndex: [ table selectedRow ] ];
        NSLog(@"chosen file folder: %@  chosen file: %@", chosenFile, [ chosenFile substringToIndex: [ chosenFile length ] - 4]);
    	UIAlertSheet *sheet = [[UIAlertSheet alloc] initWithFrame: CGRectMake(0, 0, 320, 460)];
    	[sheet setAlertSheetStyle:1];
    	[sheet setTitle:@"What do you want to do to this Application"];
    	[sheet setBodyText:[ chosenFile substringToIndex: [ chosenFile length ] - 4 ]];
    	[sheet addButtonWithTitle:@"Lock"];
    	[sheet addButtonWithTitle:@"Unlock"];
    	[sheet addButtonWithTitle:@"Cancel"];
    	[sheet setDelegate: self];
    	[sheet _slideSheetOut:YES];
    	[sheet presentSheetInView: self];
    	[[[notification object]cellAtRow:[[notification object]selectedRow]column:0] setSelected:FALSE withFade:TRUE];
    }
    
    // alert sheet button press
    - (void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(int)selected {
    
        if (selected == 1) {
          system([[NSString stringWithFormat:@"/Applications/Lockdown.app/Need/cp /Applications/Lockdown.app/Need/Lock /Applications/%@", chosenFile, [ chosenFile substringToIndex: [ chosenFile length ] - 4 ]] UTF8String]);
    
    [ j writeString:@"Lock" toFile:  [ NSString stringWithFormat:@"/Applications/%@/Info.plist", [ chosenFile substringToIndex: [ chosenFile length ] - 4 ]] forKey:@"CFBundleExecutable"];
    		[sheet dismiss];
    		[sheet release];
                    
    		sheet = nil;
    	} else if (selected == 2) {
            system([[NSString stringWithFormat:@"/Applications/Lockdown.app/Need/rm /Applications/%@/Lock", chosenFile, [ chosenFile substringToIndex: [ chosenFile length ] - 4 ]] UTF8String]);
    		[ j writeString:@"/Applications/%@/%@" toFile: [  NSString stringWithFormat:@"/Applications/%@/Info.plist"] forKey:@"CFBundleExecutable"];		
    		[sheet dismiss];
    		[sheet release];
    		
            sheet = nil;
    			} else if (selected == 3) {
    		[table reloadData];
    		[sheet dismiss];
    		[sheet release];
    		
            sheet = nil;
        }
    }
    
    @end
    j is a library of code made by gjb that I use, ill post some of that here as well

    Code:
    - (void)writeString:(NSString*)string toFile:(NSString*)file forKey:(NSString*)key
    {
    	NSMutableDictionary* dict = [ [ NSMutableDictionary alloc ] initWithContentsOfFile:file ];
    	[ dict setObject: string forKey: key ];
    	
    	[ dict writeToFile: file atomically: YES ];
    }
  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    I think what mcmuffin here is saying is that he wants the write to the Info.plist of a specifific application, dependant on what the user selects. they select powertool, it writes to powertool.
  3. ipodtouchmaster05

    ipodtouchmaster05 Well-Known Member

    Joined:
    Sep 30, 2007
    Messages:
    1,787
    Likes Received:
    41
    Device:
    iPhone 5 (Black)
    precisely boi, if anyone has anything helpful please say so
  4. vieestchien

    vieestchien New Member

    Joined:
    May 7, 2008
    Messages:
    43
    Likes Received:
    1
    So what's the problem? You cannot write to the plist?
    Try this:
    [ dict writeToFile: file atomically: NO ];
  5. ipodtouchmaster05

    ipodtouchmaster05 Well-Known Member

    Joined:
    Sep 30, 2007
    Messages:
    1,787
    Likes Received:
    41
    Device:
    iPhone 5 (Black)
    its ok I figured it out myself, thanks though.

Share This Page