2012-12-05 55 views
1

我是想在我的應用程序使用startMonitoringSignificantLocationChanges,但我有一些問題,我希望得到一些幫助:startMonitoringSignificantLocationChanges可以終止我的應用程序

  1. 爲了一個共同的應用,如果應用程序進入的背景下,10分鐘後,系統可以殺死app.if我使用startMonitoringSignificantLocationChanges,當我進入後臺兩個小時後,我的應用程序沒有終止,因爲我點擊圖標,應用程序將進入最後一個退出頁面。如果應用程序被殺死,當你點擊圖標時,你會首先看到默認頁面。所以我的問題是使用startMonitoringSignificantLocationChanges我的應用程序沒有被系統殺死後輸入背景10分鐘?

  2. 如果我關閉手機,並重新啓動手機,當顯著位置的變化,我的應用程序是否可以激活,我期待的蘋果開發文檔就回答yes.so我測試:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    
    
    if([CLLocationManager significantLocationChangeMonitoringAvailable]){ 
    [self log:@"sigAvailable=YES"]; 
    } 
    // Override point for customizatio-n after application launch. 
    
    id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]; 
    
    if (locationValue) 
    { 
    // create a new manager and start checking for sig changes 
    [self log:@"didFinishLaunchingWithOptions location key"]; 
    m_locManager = [[CLLocationManager alloc] init]; 
    [self log:@"didFinishLaunchingWithOptions created manager"]; 
    m_locManager.delegate = self; 
    [self log:@"didFinishLaunchingWithOptions set delegate"]; 
    [m_locManager startMonitoringSignificantLocationChanges]; 
    [self log:@"didFinishLaunchingWithOptions monitoring sig changes"]; 
         // do send local notification 
    return YES; 
        } 
    
    [self log:@"didFinishLaunchingWithOptions"]; 
    return YES; 
        } 
    

    我的問題:當重新啓動手機和本地通知,上面的代碼運行並記錄「didFinishLaunchingWithOptions位置鍵」等,如果我發送上述代碼的本地通知,如果用戶將收到?

回答

2
  1. 在iOS 6中有對地圖的新功能,停止位置更新 它有助於喚醒應用收到位置更新。 link

    locationManager.pausesLocationUpdatesAutomatically

另見all others

  1. 您的應用可以在設備啓動時啓動,如果它的VOIP。 看到這個apple doc

本地通知加入

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 




// creating local notification 
    Class cls = NSClassFromString(@"UILocalNotification"); 
    if (cls) 
    { 
     UILocalNotification *notification = [launchOptions objectForKey: 
              UIApplicationLaunchOptionsLocalNotificationKey]; 

     if (notification) 
     { 
      NSString *reminderText = [notification.userInfo 
             objectForKey:kRemindMeNotificationDataKey]; 
      NSLog(@"notification text:%@",reminderText); 
      // [viewController._msgTextView setText:reminderText]; 
     } 
    } 

    application.applicationIconBadgeNumber = 0; 

,您可以在

- (void)application:(UIApplication *)application 
didReceiveLocalNotification:(UILocalNotification *)notification 
{ 
    NSLog(@"application:didReceiveLocalNotification:"); 
} 

處理它們,你可以安排本地通知在

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 

Class cls = NSClassFromString(@"UILocalNotification"); 
      if (cls != nil) 
      { 
       UILocalNotification *notif = [[cls alloc] init]; 
       notif.fireDate = notifyDate; 
       notif.timeZone = [NSTimeZone defaultTimeZone]; 
       notif.alertBody = AlertMsg; 
       notif.soundName = UILocalNotificationDefaultSoundName; 
       notif.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]+1; 
       notif.alertAction = @"Show me"; 
       [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
} 
} 
+0

謝謝爲了您的答案,我想知道如果我的問題答案是正確的。並且不是所有設備都使用ios6.and我的應用程序不是voip – pengwang

+1

只有ios 6停止位置更新以改善電池。 ios 5正常工作。如果您的應用不是VOIP,則無法啓動您的應用。 – HDdeveloper

+0

如果我可以在發生重大位置更改時發送本地通知?我的應用已關閉 – pengwang

相關問題