• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            攀升·Uranus


            Something Different,Something New
            數據加載中……

            iOS 4后臺多任務

            今天調查了下IOS 4.0 支持的多任務的事宜,系統是4.2, 初步結果如下:

             

            Ios 4.0 多任務不是傳統意義上的多任務。只是把程序的狀態保存起來,程序掛起。因為Apple還沒準備好多任務同時運行,

            主要是因為batterymemory這兩個問題還沒有解決。

             

            現在IOS 4多任務支持的類型(官網):  

            §  Background audio

            §  Voice over IP

            §  Background location 

            §  Push notifications

            §  Local notifications

            §  Task finishing - If your app is in mid-task when your customer leaves it, the app can now keep running to finish the task.

            §  Fast app switching - All developers should take advantage of fast app switching, which allows users to leave your app and come right back to where they were when they left - no more having to reload the app.

             

            我使用的是Task finishing 既當用戶掛起程序時,如果還有task沒完成,可以把改task完成。

             

            但這個是有限制的,時間的限制,就是說你的后臺程序不能執行超過某個時間。

            我剛才打log看了,系統返回500s,既是8分鐘,8分鐘如果還沒執行完,就會自動把我們程序結束。


            代碼如下

            #pragma mark -

            #pragma mark Background Task Handle

            - (void)applicationDidEnterBackground:(UIApplication *)application {


            // Request permission to run in the background. Provide an 

            // expiration handler in case the task runs long.

            NSAssert(self->bgTask == UIBackgroundTaskInvalid, nil);

            self->bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{

            // Synchronize the cleanup call on the main thread in case

            // the task catully finished at around the same time.

            dispatch_async(dispatch_get_main_queue(), ^{

            if (UIBackgroundTaskInvalid != self->bgTask) {

            [application endBackgroundTask:self->bgTask];

            self->bgTask = UIBackgroundTaskInvalid;

            }

            });

            }];

            // Start the long-running task and return immediately.

            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), 

              ^{

              // Do the work assoicated with the task.

              for(int i = 0; i  < 1000; i++) {

                                                              //request network.

                                                              NSLog(@"hahah %d, Time Remain = %f", i, [application backgroundTimeRemaining]);

                                                       }

              // Synchronize the cleanup all on the main thread in case

              // the task catully finished at around the same time. 

              dispatch_async(dispatch_get_main_queue(), ^{

              

              if (UIBackgroundTaskInvalid != self->bgTask) {


              [application endBackgroundTask:self->bgTask];

              self->bgTask = UIBackgroundTaskInvalid;

              }

              });

              });

            }

            #pragma mark -

            #pragma mark Local Notifications

            - (void)scheduleAlarmForDate:(NSDate *)theDate {

            UIApplication *app = [UIApplication sharedApplication];

            NSArray *oldNotifications = [app scheduledLocalNotifications];

            // Clear out the old notification before scheduling a new one.

            if (0 < [oldNotifications count]) {

            [app cancelAllLocalNotifications];

            }

            // Create a new notification

            UILocalNotification *alarm = [[UILocalNotification alloc] init];

            if (alarm) {


            alarm.fireDate = theDate;

            alarm.timeZone = [NSTimeZone defaultTimeZone];

            alarm.repeatInterval = 0;

            alarm.soundName = @"ping.caf";//@"default";

            alarm.alertBody = [NSString stringWithFormat:@"Time to wake up!Now is\n[%@]", 

              [NSDate dateWithTimeIntervalSinceNow:10]];

            [app scheduleLocalNotification:alarm];

            [alarm release];

            }

            有問題留言,或者微博:http://t.sina.com.cn/passionuranus

            posted on 2011-01-06 11:58 攀升 閱讀(1002) 評論(0)  編輯 收藏 引用 所屬分類: iOS

            久久人人超碰精品CAOPOREN| 亚洲国产精品无码久久一线 | 国产AV影片久久久久久| 久久久91精品国产一区二区三区 | 国产亚洲精午夜久久久久久| 久久伊人影视| 99久久成人国产精品免费| 人人狠狠综合久久亚洲88| 久久无码国产专区精品| 99久久久精品| 久久精品国产99国产精品亚洲| 国产麻豆精品久久一二三| 精品久久久久久国产三级| 亚洲va久久久噜噜噜久久狠狠| 91精品国产91久久久久福利| 亚洲欧美一级久久精品| 91精品国产综合久久久久久| 亚洲欧洲精品成人久久奇米网 | 欧美伊人久久大香线蕉综合| 久久综合狠狠色综合伊人| 亚洲中文久久精品无码| 欧美日韩中文字幕久久久不卡 | 久久乐国产精品亚洲综合| 欧美牲交A欧牲交aⅴ久久| 久久免费香蕉视频| 久久精品国产精品亚洲人人| 大伊人青草狠狠久久| 国产精品久久久久影院色| 奇米影视7777久久精品| 7777久久久国产精品消防器材| 日韩欧美亚洲综合久久影院Ds| 亚洲精品国产成人99久久| 国产91色综合久久免费| AV色综合久久天堂AV色综合在| 色88久久久久高潮综合影院| 久久久久亚洲精品日久生情| 久久国产亚洲精品| 无码超乳爆乳中文字幕久久 | 最新久久免费视频| 久久久久亚洲AV成人网人人网站 | 一级女性全黄久久生活片免费 |