【问题标题】:When iOS simulator starts, is it possible to automatically load the Web Inspector?iOS模拟器启动时,是否可以自动加载Web Inspector?
【发布时间】:2012-10-15 22:13:57
【问题描述】:

我在 Safari 中使用带有闪亮的新 Web Inspector 的 iOS 6 模拟器。

问题:是否可以在 iOS 6 Web 应用程序加载时自动加载 Web Inspector?

我正在使用 PhoneGap/Cordova,并且在启动时加载了很多 javascript。我广泛使用 console.log() 进行调试,并希望它在应用程序启动后加载 Web Inspector。

目前,当我在 Xcode 上点击 Run 时,应用程序会加载,我在我的第一个函数上 setTimeout,这样我就可以冲到 Safari 并在该页面上附加 Web Inspector。

我更愿意删除此步骤并添加一个可以直接加载 Web Inspector 的自动步骤。

还有其他解决方案吗?

【问题讨论】:

    标签: ios6 ios-simulator xcode4.5 web-inspector


    【解决方案1】:

    这是部分解决方案。这会一键打开 Safari 的调试窗口,效果好很多,但不是自动的。

    在您的 Mac 上打开 Script Editor(Command + 空格键并输入脚本编辑器)

    粘贴这段代码:

    -- `menu_click`, by Jacob Rus, September 2006
    -- 
    -- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
    -- Execute the specified menu item.  In this case, assuming the Finder 
    -- is the active application, arranging the frontmost folder by date.
    
    on menu_click(mList)
        local appName, topMenu, r
    
        -- Validate our input
        if mList's length < 3 then error "Menu list is not long enough"
    
        -- Set these variables for clarity and brevity later on
        set {appName, topMenu} to (items 1 through 2 of mList)
        set r to (items 3 through (mList's length) of mList)
    
        -- This overly-long line calls the menu_recurse function with
        -- two arguments: r, and a reference to the top-level menu
        tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
            (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
    end menu_click
    
    on menu_click_recurse(mList, parentObject)
        local f, r
    
        -- `f` = first item, `r` = rest of items
        set f to item 1 of mList
        if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
    
        -- either actually click the menu item, or recurse again
        tell application "System Events"
            if mList's length is 1 then
                click parentObject's menu item f
            else
                my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
            end if
        end tell
    end menu_click_recurse
    
    menu_click({"Safari", "Develop", "IOS Simulator", "index.html"})
    

    模拟器打开后,单击脚本上的运行(您可能需要第一次在设置中允许脚本编辑器)。

    (可选)您可以将脚本保存为应用程序,这样您就不必打开脚本编辑器。

    (这个回答是加拉丁之前回答的更详细的版本)

    【讨论】:

    • 对于更懒惰的解决方案,请尝试转到 System Preferences &gt; Keyboard &gt; Shortcuts 并为菜单标题 localhost 或您的 URL 在“开发”菜单中的任何内容添加一个“应用程序快捷方式”。
    【解决方案2】:

    现在是 2014 年年中,据我所知,仍然没有优雅的解决方案,但我喜欢在应用的初始化代码中添加一个带有 setTimeout 的短暂暂停的想法。如果无法添加 setTimeout 调用,您还可以从 Safari 控制台发出 window.location.reload() 以重新启动您的应用程序,从而获得全面调试的好处。

    【讨论】:

      【解决方案3】:

      1) 在 OnDeviceReady 处理程序中添加调试器;

      onDeviceReady: function() {
          debugger;
          // the rest of your device ready code
      }
      

      2) 通过 xcode 或 cmdline 运行应用程序。

      3) 通过 Safari->Develop->Simulator->Appname -> index file 附加调试器

      4) 打开safari的控制台视图,输入:

      Window.location = "";
      

      5) 应用程序将重新加载,调试器将附加到 onDeviceReady() 的第一行。

      6) 正常调试。

      【讨论】:

        猜你喜欢
        • 2010-12-17
        • 2011-10-28
        • 1970-01-01
        • 2015-01-06
        • 2020-12-22
        • 2013-07-14
        • 2015-05-31
        • 2013-10-08
        • 2018-03-07
        相关资源
        最近更新 更多