2011-11-04 88 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

听起来不错。我不再和ios一起工作,但我会把这个给你,因为它看起来像我所要求的。也许别人可以验证? – 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:就像它通过在iphone模拟器上点击Debug-> Location-> Custom Location。这看起来像它所做的就是设置一个浮点数。 – JonnyBoy

相关问题