I proposed an automatic solution to the problem of changing the time, which includes the hacked swackling method: https://stackoverflow.com/a/212618/ I assume that this should also work to change the time zone accordingly.
I needed to check the application automatically, which required a sys time change. I did what Tom suggested: the happy hacker swizzling method.
For demonstration purposes, I only change [NSDate date] , but not [NSDate dateWithTimeIntervalSince1970:] .
First you need to create your own class method, which will be used as the new [NSDate date]. I implemented it to just shift time to constant time.
int timeDifference = 60*60*24; //shift by one day NSDate* (* original)(Class,SEL) = nil; +(NSDate*)date{ NSDate* date = original([NSDate class], @selector(date)); return [date dateByAddingTimeInterval:timeDifference]; }
It is still pretty easy. Now comes an interesting role. We get methods from both classes and the exchange implementation (it worked for me in AppDelegate, but not in my UITests class). To do this, you will need to import objc/runtime.h .
Method originalMethod = class_getClassMethod([NSDate class], @selector(date)); Method newMethod = class_getClassMethod([self class], @selector(date));
Sebastian Hojas Jan 14 '16 at 15:28 2016-01-14 15:28
source share