2011-11-04 13 views
9

Ho appena aggiornato XCode 4.2 e vedo una funzionalità interessante che consente di impostare manualmente la posizione del dispositivo. Qualcuno sa di un modo per realizzare la stessa cosa a livello di programmazione? Mi piacerebbe impostare la posizione in alcuni test di unità.Impostazione programmatica del simulatore iphone

+0

http://stackoverflow.com/questions/214416/set-the-location-in-iphone-simulator –

+1

non credo che aiuta. Quello che sta dicendo è sovrascrivere il callback da CLLocationManager. Ma il problema che sto vedendo è che nei miei test di unità, il callback non viene affatto. Speravo che ci fosse qualcosa di simile: [NSApplication setLatitude: lat longitude: lng] – JonnyBoy

+0

quindi @JonnyBoy l'hai capito? mi piacerebbe usare anche questo! – abbood

risposta

9

Di seguito AppleScript consente di impostare la posizione del simulatore iOS. Dovrebbe essere possibile integrare questo tipo di script in uno script di unit test o far generare allo script gli equivalenti AppleEvents.

tell application "iOS Simulator" 
    activate 
end tell 

tell application "System Events" 
    tell process "iOS Simulator" 
     tell menu bar 1 
      tell menu bar item "Debug" 
       tell menu "Debug" 
        tell menu item "Location" 
         click 
         tell menu "Location" 
          click menu item "Custom Location…" 
         end tell 
        end tell 
       end tell 
      end tell 
     end tell 

     tell window 1 
      set value of text field 1 to "40.69" 
      set value of text field 2 to "-74.045" 
      click button "OK" 
     end tell 

    end tell 
end tell 
+0

Sembra buono. Non sto più lavorando con iOS, ma te lo darò perché sembra che faccia quello che stavo chiedendo. Forse qualcun altro può verificare? – JonnyBoy

2

È possibile utilizzare l'inclusione condizionale del preprocessore; controllare la macro TARGET_IPHONE_SIMULATOR in questo modo:

#if TARGET_IPHONE_SIMULATOR 
    float longitude = 39.1234; 
    // etc  
#else 
    float longitude = myLocationManager.longitude 
#endif 
+2

Immagino di non essere stato abbastanza chiaro. Sto cercando un modo per un'istanza CLLocationManager per inviare un http://developer.apple.com/library/ios/DOCUMENTATION/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html#//apple_ref/occ/intfm/ CLLocationManagerDelegate/locationManager: didUpdateToLocation: fromLocation: come farebbe clic su Debug-> Location-> Custom Location sul simulatore iphone. Questo sembra che tutto ciò che fa è impostare un float. – JonnyBoy

Problemi correlati