2011-11-04 2 views
9

방금 ​​XCode 4.2로 업데이트했으며 장치 위치를 수동으로 설정할 수있는 멋진 기능을 제공합니다. 누구든지 프로그래밍 방식으로 동일한 작업을 수행하는 방법을 알고 있습니까? 일부 단위 테스트에서 위치를 설정하고 싶습니다.프로그래밍 방식으로 iphone 시뮬레이터 위치 설정

+0

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

+1

나는이 도움이 생각하지 않습니다. 무슨 말인지 CLLocationManager에서 콜백을 재정의하는 것입니다. 하지만 내가보기에 문제는 내 단위 테스트에서 콜백이 전혀 오지 않는다는 것입니다. 나는 다음과 같은 것이 있었으면합니다 : [NSApplication setLatitude : lat longitude : lng] – JonnyBoy

+0

그래서 @JonnyBoy가 이것을 알아 냈습니까? 나는 이것을 잘 사용하고 싶다! – abbood

답변

9

다음 AppleScript로 당신이 iOS 시뮬레이터의 위치를 ​​설정할 수 있습니다. 이러한 종류의 스크립트를 단위 테스트 스크립트에 통합하거나 스크립트에서 동등한 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

좋은 소리. 나는 이오스와 더 이상 일하지 않을 것이다. 그러나 나는 당신이 요구하고있는 것처럼 보이기 때문에 나는이 것을 당신에게 줄 것이다. 누군가 다른 사람을 확인할 수 있습니까? – JonnyBoy

2

전 처리기 조건부 포함을 사용할 수 있습니다. 이 같은 TARGET_IPHONE_SIMULATOR 매크로를 확인하십시오

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

나는 충분히 명확하지 않았던 것 같아. CLLocationManager 인스턴스가 http://developer.apple.com/library/ios/DOCUMENTATION/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html#//apple_ref/occ/intfm/을 보낼 수있는 방법을 찾고 있습니다. CLLocationManagerDelegate/locationManager : didUpdateToLocation : fromLocation : 아이폰 시뮬레이터에서 Debug-> Location-> Custom Location을 클릭하면됩니다. 이 모든 것은 플로트로 설정되어있는 것처럼 보입니다. – JonnyBoy

관련 문제