設定iphone主題 代碼

來源:互聯網
上載者:User

#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];

}

    NSRangerange = [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;

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.