gpt4 book ai didi

ios - 后台获取什么时间用完了?

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

我想知道当backgroundfetch模式时实际设备会发生什么

例如下面的代码:

第 1 步:启用“后台获取”功能

第二步:设置 AppDelegate.swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

let settings = UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert, categories: nil)

UIApplication.sharedApplication().registerUserNotificationSettings(settings)

UIApplication.sharedApplication().setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)

return true;





}

第三步:在AppDelegate.swift中注册应用事件,注册完成处理器

func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

println("Complete");

completionHandler(UIBackgroundFetchResult.NewData)



getData();



}



func getData() -> Void{

var url = "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?apikey=xxxxxx&limit=20";

var request = NSURLRequest(URL: NSURL(string: url));



NSURLConnection.sendAsynchronousRequest(request,queue: NSOperationQueue.mainQueue()) {

(response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in

var moviesResult = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as NSDictionary;

var movies: [NSDictionary]=[];

movies = moviesResult["movies"] as [NSDictionary];

var localNotification:UILocalNotification = UILocalNotification()

localNotification.alertAction = "Testing notifications on iOS8"

localNotification.alertBody = "Movie Count : \(movies.count)"

localNotification.fireDate = NSDate(timeIntervalSinceNow: 1)

UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

}





}

getdata函数什么时候执行?

有时间程序完全关闭,

一直在运行?

最佳答案

Apple 不对后台提取的执行频率提供任何保证。这取决于许多因素,包括手机的当前状态(即,您使用的是 WiFi 还是蜂窝网络、强/弱信号、其他应用程序正在做什么、您的应用程序返回新数据的频率等)和设置(它不会例如在低功耗模式下运行)。它会按照 Apple 认为合理的频率运行。

如果您认为他们做出了错误的判断调用,您将需要使用另一种机制来触发您的 getData 方法。

关于ios - 后台获取什么时间用完了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35411240/

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