#import <UIKit/UIKit.h>
//#import "AppDelegate.h"
#import <spawn.h>
#import <sys/wait.h>
#import <CoreFoundation/CoreFoundation.h>
void setSystemTimeZone(NSString *timeZoneIdentifier) {
pid_t pid;
int status;
const char *argv[] = {"/usr/bin/env", "launchctl", "setenv", "TZ", [timeZoneIdentifier UTF8String], NULL};
posix_spawn(&pid, argv[0], NULL, NULL, (char * const *)argv, NULL);
waitpid(pid, &status, 0);
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
NSLog(@"Time zone changed to %@", timeZoneIdentifier);
CFNotificationCenterPostNotification(
CFNotificationCenterGetDarwinNotifyCenter(),
CFSTR("com.apple.system.timezone"),
NULL,
NULL,
true
);
} else {
NSLog(@"Failed to change time zone");
}
}
int main(int argc, char * argv[]) {
@autoreleasepool {
// Example usage
setSystemTimeZone(@"America/New_York");
//return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
return 0;
}
}
在设置中能改成功,但在其他应用中,不生效,比如Safari中也不生效,
杀死进程,killall -9 MobileSafari killall -9 Preferences 仍然无效,不更新时区
请老师帮我看一下,如何修改代码,多谢