想要在10天后举行活动

时间:2023-01-22 18:59:58

Wants fire an event after 10 days, Let's say I have an expiry date to show image saved in my app folder. I am saving download time of asset and I want to check that time with 10 days after downloaded time. If that crosses 10 days that asset should remove automatically from app folder.

要在10天后触发事件,假设我有一个过期日期来显示保存在应用程序文件夹中的图像。我正在节省下载时间的资产,我想在下载时间后的10天内查看时间。如果超过10天,该资产将自动从应用程序文件夹中删除。

I know some of the options we have like:

我知道我们有一些选择:

1. GCD:

1。肾小球囊性肾病:

int parameter1 = 12;
float parameter2 = 144.1;

// Delay execution of my block for 10 seconds.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    NSLog(@"parameter1: %d parameter2: %f", parameter1, parameter2);
});

2. Local Notifications/EventKit:

2。当地通知/ EventKit:

Note: it shouldn't throw any alert, It should delete asset in the background from app folder.

注意:它不应该抛出任何警告,它应该从app文件夹的后台删除资产。

Is there any way to trigger the method with duration.

是否有方法以持续时间触发方法。

1 个解决方案

#1


1  

I keep the date that the file was added on the device in NSUserDefaults.

我保留了在NSUserDefaults中添加到设备上的文件的日期。

Then when AppDelegate's application(_, didFinishLaunchingWithOptions:) would fire I would check if 10 days have passed from the last purge. If true I would purge again, if false I would not do anything.

然后,当AppDelegate的应用程序(_,didFinishLaunchingWithOptions:)启动时,我会检查上一次清除是否已经过去了10天。如果是真的,我会再清洗;如果是假的,我不会做任何事。

#1


1  

I keep the date that the file was added on the device in NSUserDefaults.

我保留了在NSUserDefaults中添加到设备上的文件的日期。

Then when AppDelegate's application(_, didFinishLaunchingWithOptions:) would fire I would check if 10 days have passed from the last purge. If true I would purge again, if false I would not do anything.

然后,当AppDelegate的应用程序(_,didFinishLaunchingWithOptions:)启动时,我会检查上一次清除是否已经过去了10天。如果是真的,我会再清洗;如果是假的,我不会做任何事。