设置iphone主题 代码

#define THEME_PLIST_PATH @"/private/var/mobile/Library/Preferences/com.saurik.WinterBoard.plist"

#define THEME_PATH @"/Library/Themes/"

 

#import <Foundation/Foundation.h>

 

NSMutableArray *getThemeInfo()

{

//获取winterBoard的plist信息

NSDictionary *saurikDict = [NSDictionary dictionaryWithContentsOfFile:THEME_PLIST_PATH];

NSMutableArray *themeArr = nil;

if (saurikDict)

{

//获取theme列表信息

themeArr = [NSMutableArray arrayWithArray: [saurikDict objectForKey:@"Themes"]];

}

return themeArr;

}

 

//设置主题信息

NSMutableArray* changeThemeInfo(NSString* themePath)

{

if ([themePath hasSuffix:@"/"]) 

{

themePath = [themePath substringToIndex:[themePath length]-1];

}

    NSRange range = [themePath rangeOfString:@"/" options:NSBackwardsSearch];

 

NSString *themeName = themePath;

if (range.length > 0 )

themeName = [themeName substringFromIndex:range.location+range.length];

NSMutableArray *themes = getThemeInfo();

BOOL isSameTheme = FALSE;

//判断主题是否存在于列表中

for (NSMutableDictionary *dict in themes)  

{

NSString *themeStr = [dict objectForKey:@"Name"];

if ([themeStr isEqualToString:themeName])

{

NSString *themeKey = [dict objectForKey:@"Active"];

if (themeKey)

{

[dict setObject:[NSNumber numberWithInt:![themeKey intValue]] forKey:@"Active"];

isSameTheme = YES;

break;

}

}

}

//如果是新主题

if (!isSameTheme)

{

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:TRUE], @"Active", themeName, @"Name", nil];

[themes addObject:dict];

}

return themes;

}

 

//主题应用

void applyTheme(NSString *themePath)

{

NSMutableArray *themes = changeThemeInfo(themePath);

 

NSMutableDictionary *saurikDict = [NSMutableDictionary dictionaryWithContentsOfFile:THEME_PLIST_PATH];

NSLog(@"themes == %@",themes);

if (themes)

{

[saurikDict removeObjectForKey:@"Themes"];

[saurikDict setObject:themes forKey:@"Themes"];

[saurikDict writeToFile:THEME_PLIST_PATH atomically:YES];

system("killall SpringBoard");

}

else 

{

NSLog(@"the array is nil");

}

 

}

 

 

int main(int argc, char *argv[]) 

{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

if (argc < 2)

{

NSLog(@"you need a parameter");

}

NSString *themeName = nil;

if (argc == 2)

{

themeName = [NSString stringWithFormat:@"%s",argv[1]];

}

if (themeName == nil)

{

NSLog(@"your parameter is error such as: ./ThemeApply Black  **** Black not '/'");

}

else

{

NSLog(@"themeName === %@",themeName);

applyTheme(themeName);

NSLog(@"apply themeName successfully");

}

[pool release];

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值