首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当iOS模拟器启动时,是否可以自动加载Web Inspector?

当iOS模拟器启动时,是否可以自动加载Web Inspector?
EN

Stack Overflow用户
提问于 2012-10-26 00:54:44
回答 3查看 3.1K关注 0票数 31

我使用Safari6模拟器和iOS中闪亮的新Web Inspector。

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

我使用的是PhoneGap/Cordova,并在启动时加载了大量的javascript。我经常使用console.log()进行调试,并希望它在应用程序启动时加载Web Inspector。

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

我更喜欢删除这一步,并添加一个自动步骤,可以直接加载Web Inspector。

还有其他的解决方案吗?

EN

回答 3

Stack Overflow用户

发布于 2015-04-23 22:37:08

这是一个部分解决方案。这将通过一次单击打开Safari的调试窗口,这要好得多,但不是自动的。

在mac上打开Script Editor (Command +空格键并在脚本编辑器中键入)

粘贴以下代码:

代码语言:javascript
运行
复制
-- `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"})

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

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

(这个答案是Galatin之前答案的更详细的版本)

票数 3
EN

Stack Overflow用户

发布于 2014-05-31 00:14:59

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

票数 2
EN

Stack Overflow用户

发布于 2015-10-23 22:21:46

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

代码语言:javascript
运行
复制
onDeviceReady: function() {
    debugger;
    // the rest of your device ready code
}

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

3)通过Safari -> Develop>Simulator->Appname->索引文件附加调试器

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

代码语言:javascript
运行
复制
Window.location = "";

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

6)正常调试。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13073496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档