22

Safari の iOS Web デバッガーは非常に簡単ですが、シミュレーターを再起動するたびに終了します。ビルドのたびにメニューから再度開くのが面倒なだけでなく、起動時に発生する動作をデバッグするのが難しくなります。

ビルドのたびに Safari デバッガーを自動的に開くように Xcode でトリガーを設定する方法はありますか? あるいは、ビルドを実行してすぐにデバッガーを開くシェル スクリプトまたは Automator アクションをビルドする方法はありますか?

4

5 に答える 5

12

これは部分的な解決策です。これにより、ワンクリックでSafariのデバッグウィンドウが開きます。これははるかに優れていますが、自動ではありません。

Mac で開きScript Editorます (コマンド + スペース バーを押して、スクリプト エディターに入力します)。

次のコードを貼り付けます。

-- `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", "Simulator", "index.html"})

シミュレーターが開いたら、スクリプトの [実行] をクリックします (初回は設定でスクリプト エディターを許可する必要がある場合があります)。

(オプション) スクリプトをアプリとして保存できるため、スクリプト エディターを開く必要はありません。

于 2015-04-23T14:37:42.573 に答える
3

setTimeout() を使用して、ウィンドウを Safari に切り替えてブレークポイントを設定するのに十分な時間を与えることを説明 する重複としてマークする必要がある質問があります。

このようなもので、startMyApp はアプリのブートストラップ関数です。

setTimeout(function () {
  startMyApp();
}, 20000);

それはスーパーゲットーですが、機能します。ループを閉じるために、http://www.apple.com/feedback/safari.htmlからも機能リクエストを送信しました。

于 2013-05-11T00:27:17.563 に答える
2

@Prisonerの回答を拡張すると、WKWebViewを使用すると次のことができます。

    let contentController:WKUserContentController = WKUserContentController()


    let pauseForDebugScript = WKUserScript(source: "window.alert(\"Go, turn on Inspector, I'll hold them back!\")",
                                           injectionTime: WKUserScriptInjectionTime.AtDocumentStart,
                                           forMainFrameOnly: true)
    contentController.addUserScript(pauseForDebugScript)

    let config = WKWebViewConfiguration()
    config.userContentController = contentController
    //Init browser with configuration (our injected script)
    browser = WKWebView(frame: CGRect(x:0, y:0, width: view.frame.width, height: containerView.frame.height), configuration:config)

WKUIDelegateまた重要なことは、プロトコルからアラートハンドラーを実装することです

//MARK: WKUIDelegate
func webView(webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String,
             initiatedByFrame frame: WKFrameInfo, completionHandler: () -> Void) {

    let alertController = UIAlertController(title: message, message: nil,
                                            preferredStyle: UIAlertControllerStyle.Alert);

    alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel) {
        _ in completionHandler()}
    );

    self.presentViewController(alertController, animated: true, completion: {});
}

エラーが発生する可能性がある場合に備えて、UIAlertController:supportedInterfaceOrientations was invoked recursively次の拡張子を追加します(このSO Answerから

extension UIAlertController {     
    public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Portrait
    }
    public override func shouldAutorotate() -> Bool {
        return false
    }
}
于 2016-11-03T00:34:05.220 に答える
-4

うーん、それはできないと思いますが、Web デバッガーで「CTRL+R」を押すだけでできます。

于 2013-02-20T03:41:44.610 に答える