2012-03-29 63 views
11

我正在製作一個應用程序,我需要顯示在後臺運行的應用程序的名稱。我做了R & D,並知道我們只能知道蘋果的應用程序,如照片,相機等,但我不知道如何。請幫助我,如果你知道如何讓後臺運行的APPS 後臺運行的進程我已經使用了JUST名字下面的方法如何獲取後臺運行應用程序的名稱

- (NSArray *)runningProcesses { 

    int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0}; 
    size_t miblen = 4; 

    size_t size; 
    int st = sysctl(mib, miblen, NULL, &size, NULL, 0); 

    struct kinfo_proc * process = NULL; 
    struct kinfo_proc * newprocess = NULL; 

    do { 

     size += size/10; 
     newprocess = realloc(process, size); 

     if (!newprocess){ 

      if (process){ 
       free(process); 
      } 
      return nil; 
     } 

     process = newprocess; 
     st = sysctl(mib, miblen, process, &size, NULL, 0); 

    } while (st == -1 && errno == ENOMEM); 

    if (st == 0){ 

     if (size % sizeof(struct kinfo_proc) == 0){ 
      int nprocess = size/sizeof(struct kinfo_proc); 

      if (nprocess){ 

       NSMutableArray * array = [[NSMutableArray alloc] init]; 

       for (int i = nprocess - 1; i >= 0; i--){ 

        NSString * processID = [[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid]; 
        NSString * processName = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm]; 

        NSDictionary * dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName, nil] 
                     forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName", nil]]; 
        [processID release]; 
        [processName release]; 
        [array addObject:dict]; 
        [dict release]; 
       } 

       free(process); 
       return [array autorelease]; 
      } 
     } 
    } 

    return nil; 
} 

如果你認爲它不可能那麼好心,看一下這個程序http://itunes.apple.com/us/app/sys-activity-manager-for-memory/id447374159?mt=8。我也有一個解決方案,但它不是一個正確的方法(我在這個問題下面的最後一個評論中提到過)。

謝謝。

+0

你有沒有通過這個http://forrst.com/posts/UIDevice_Category_For_Processes-h1H – 2012-03-29 04:32:26

+0

也許它在上面的代碼中表示ProcessName? – 2012-03-29 04:32:53

+0

@AdamShiemke,這就是讓進程不是應用程序的名稱,進程是指所有後臺運行服務 – HarshIT 2012-03-29 04:35:22

回答

0

我不認爲這是可能的,但像你這樣的其他人已經非常參與同一主題並提出一些解決方法。閱讀此博客文章的更多信息:http://www.amitay.us/blog/files/how_to_detect_installed_ios_apps.php

+0

試試這個應用程序http://itunes.apple.com/us/app/sys-activity-manager-for-memory/id447374159?mt=8 – HarshIT 2012-04-10 04:32:50

+0

閱讀我發佈的最後評論以下問題 – HarshIT 2012-04-10 04:33:03

+0

開發人員從他的代碼頁面,它不再可用 – Justin 2012-04-17 03:23:57

1

我認爲在ios中不可能獲得哪些應用程序在後臺運行,因爲在ios中哪一個是前臺這一個是主動運行的應用程序和其他哪一個你正在獲取這些都是背景appps。

因此,排除您的應用程序名稱其他是後臺應用程序。

+0

請參閱http://itunes.apple.com/us/app/sys-activity-manager-for-memory/id447374159?mt=8。 ,這工作正常。這意味着這是可能的 – HarshIT 2012-05-16 04:28:07

相關問題