gpt4 book ai didi

ios - 耗时和设置日期?

转载 作者:行者123 更新时间:2023-11-29 02:55:17 25 4
gpt4 key购买 nike

这是我想要完成的:用户触摸一个按钮,然后可以将某些内容分享到 facebook。用户触摸按钮的日期已设置,并且在 24 秒内用户无法再次与 Facebook 分享任何内容。 24 秒后,用户可以将另一篇帖子分享到 Facebook。

错误与facebook无关,但与elapsedTime有关。重置 elapsedTime 后,它不会重新计数到 24。它只是停留在一个非常小的数字,如“0.0043”

这是我的代码:

-(void)postToFacebook
{
if (elapsedTime >= 24) {
[[CCDirector sharedDirector] pause];
[[CCDirector sharedDirector] stopAnimation];

CCAppDelegate *app = (CCAppDelegate*) [[UIApplication sharedApplication] delegate];


SLComposeViewController *faceBookPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

[faceBookPost setInitialText:@"test"];
[faceBookPost addURL:[NSURL URLWithString:@"http://www.google.com"]];

[[app navController] presentModalViewController:faceBookPost animated:YES];
faceBookPost.completionHandler = ^(SLComposeViewControllerResult result)
{
[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] startAnimation];
[[app navController] dismissModalViewControllerAnimated:YES];
dogeAmount.string = [NSString stringWithFormat:@"%.2LF", _doge];
[self setDate];
NSLog(@"Posted to Facebook");
};
} else if (elapsedTime < 24) {
NSLog(@"%f", elapsedTime);
}
}

这里是上面调用的 SetDate:

-(void)setDate {
NSString *dateString = [NSDateFormatter localizedStringFromDate:[NSDate date]
dateStyle:NSDateFormatterShortStyle
timeStyle:NSDateFormatterFullStyle];
defaults = [NSUserDefaults standardUserDefaults];
startTime = [NSDate date];
calendar = [NSCalendar currentCalendar];
components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:startTime];
hour = [components hour];
minute = [components minute];
NSNumber *hourNumber = [NSNumber numberWithInteger:hour];
NSNumber *minuteNumber = [NSNumber numberWithInteger:minute];
[defaults setObject:startTime forKey:@"startTime"];
[defaults setObject:hourNumber forKey:@"hour"];
[defaults setObject:minuteNumber forKey:@"minute"];
[defaults setInteger:elapsedTime forKey:@"elapsedTime"];
NSLog(@"%@",dateString);
elapsedTime = fabs([startTime timeIntervalSinceNow]);
[defaults synchronize];
}

我不知道我做错了什么。

最佳答案

.h

@property (strong, nonatomic) NSDate *dateString;

.m

- (void)share
{
double dateSinceNow = -[self.dateString timeIntervalSinceNow];

if (dateSinceNow > 24)
{
//share to facebook
}

self.dateString = [NSDate date];
}

关于ios - 耗时和设置日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23974719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com