plist modifications

Discussion in 'iOS Development' started by crizh4x, Dec 22, 2008.

  1. crizh4x

    crizh4x Active Member

    Joined:
    Sep 19, 2007
    Messages:
    4,474
    Likes Received:
    17
    Device:
    2G iPod touch
    Yes, of course I've searched relentlessly...

    I am using gojohnyboi's sample code to read/write plists...

    The code will read the plist just fine, but I can't write anything back to it.

    Steps taken to resolve issue:

    *Change plist permissions to allow full write access
    *Edited code and changed the
    Code:
    setValue
    to other things like
    Code:
    setObject 
    ,
    Code:
    setInteger
    Here is the code that doesn't seem to write the plist correctly:

    Code:
    -(IBAction) applySettings:(id) sender {
    	if (statusSwitch.on = YES) {
    		NSString *filePath = @"/System/Library/LaunchDaemons/com.iphone.utils.plist";
            NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
            [plistDict setValue:[NSString stringWithFormat:@"Interval Changed to %1.0f Seconds", [execIntSlider value]] forKey:@"ProductVersion"];
            [plistDict writeToFile:filePath atomically: YES];	
    		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success!" message:[NSString stringWithFormat:@"Interval Changed to %1.0f Seconds", [execIntSlider value]]
    		delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    		[alert show];
    		[alert release];	
    	}
    	else {
    		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Operation Incomplete" message:@"USB Execution System inactive."
    		delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    		[alert show];
    		[alert release];	
    	}
    }
    This code will read the plist just fine:

    Code:
    		NSString *filePath = @"/System/Library/LaunchDaemons/com.iphone.utils.plist";
    		NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    		NSString *value;
    		value = [plistDict objectForKey:@"StartInterval"];
    		int intHold = [value intValue];
    		execIntSlider.value = intHold;
    		[execIntLabel setText:[NSString stringWithFormat:@"%1.0f Seconds", [execIntSlider value]]];
    This is the plist itself, the "StartInterval" value is what needs changed

    Code:
    <?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
    <plist version="1.0">
    <dict> 
        <key>Label</key> 
        <string>com.iphone.utils.plist</string>
        <key>RunAtLoad</key> 
        <true/>
    <key>StartInterval</key>
        <integer>30</integer>
    <key>ProgramArguments</key> 
        <array> 
            <string>/etc/rc.local</string> 
        </array> 
    </dict> 
    </plist>
    Any help is appreciated. I'll fill in any gaps anyone might need... I think this is a strange issue. Perhaps it's because the file is in use by Launchctl? I tried running a

    Code:
    system("launchctl remove com.iphone.utils.plist")
    but after executing the app and doing a "launchctl list", it is still there.

    Thanks again!
  2. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    are you using the SDK?
  3. crizh4x

    crizh4x Active Member

    Joined:
    Sep 19, 2007
    Messages:
    4,474
    Likes Received:
    17
    Device:
    2G iPod touch
    Yes, 3.1.2 I believe.
  4. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    if im not mistaken applications compiled with the sdk can read outside the User directory but can write to them.
  5. crizh4x

    crizh4x Active Member

    Joined:
    Sep 19, 2007
    Messages:
    4,474
    Likes Received:
    17
    Device:
    2G iPod touch
    That would be understandable if it were running in the sandboxed environment in /User/Applications... It is running from /Applications with no signature. It should be just fine unless I need toolchain headers right?
  6. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    No i had the same problem with an app i made in the SDK, i could read files not in the /User directory but i couldn't write to any other directory. Its a real bummer!
  7. crizh4x

    crizh4x Active Member

    Joined:
    Sep 19, 2007
    Messages:
    4,474
    Likes Received:
    17
    Device:
    2G iPod touch
    Ok so hmm... Perhaps I can create a symlink from the daemon to my User folder? it's worth a shot I guess.
  8. ipodtouchmaster05

    ipodtouchmaster05 Well-Known Member

    Joined:
    Sep 30, 2007
    Messages:
    1,787
    Likes Received:
    41
    Device:
    iPhone 5 (Black)
    No, to write to a plist your binary needs 4755 permissions, and it cannot run like that in /Applications, or it will crash. So you will need to find a file that is used to launch your app from within your app so your app binary can be 4755 then it can write to a plist. lol kinda complicated there but look inside cydia's app folder there should b a couple binarys in there, the one that is only a few bytes take out and open with notepad, should b self explanatory from there.
  9. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    Here, I'll tell you....

    • Put the .app folder in /Applications
    • Do
      Code:
      chmod -R 0755 /Applications/APPNAME.app
    • Then,
      Code:
      ldid -S /Applications/APPNAME.app/APPNAME
    • Now, place a binary with whatever name in the /Applications/APPNAME.app with the following code in it
      Code:
      #!/bin/bash
      DIR=$(dirname "$0")
      exec "${DIR}/APPNAME"
    • Change the "CFBundleExecutable" key in the app's Info.plist to the name of the new file you just created & save
    • Now do
      Code:
      chmod -R 0755 /Applications/APPNAME.app & chmod +s /Applications/APPNAME.app/APPNAME

    That's it! Run the app, and watch it soar!
  10. crizh4x

    crizh4x Active Member

    Joined:
    Sep 19, 2007
    Messages:
    4,474
    Likes Received:
    17
    Device:
    2G iPod touch
    This is interesting... so you're saying that it isn't an SDK issue (which I was wondering how it could be since the app is running without CodeSign issues from /Applications... but rather, a permissions issue with my app itself, not the plist.

    I am very familiar with chmod and most of the bin utils, but what is the difference in 0755 and 4755? Is it an ownership permission? I thought that should be handled by chown?

    Anyway, I'll give this a shot. Thanks guys.

Share This Page