When iOS simulator starts, is it possible to automatically load the Web Inspector? - ios6

I'm using iOS 6 simulator with the shiny new Web Inspector in Safari.
Question: Is it possible to automatically load the Web Inspector when the iOS 6 web application loads?
I'm using PhoneGap/Cordova and have a lot of javascript loading on startup. I use console.log() extensively for debugging and would like it to load Web Inspector once the application starts.
Currently when I hit Run on Xcode, the app loads and I setTimeout on my first function so I can rush over to Safari and attach the Web Inspector on that page.
I'd much prefer to remove this step and add an automated step that would load the Web Inspector directly.
Any other solutions?

This is a partial solution. This opens the debug window of Safari with one click which is a lot better but not automatic.
Open Script Editor on your mac (Command + Space Bar and type in Script Editor)
Paste in this code:
-- `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"})
Once the simulator has opened, click run on your script (you might need to allow the script editor in the settings the first time).
(Optional) You can save your the scripts as an app so that you don't have to have the script editor open.
(this answer is a more detailed version of Galatin's previous answer)

It's mid-2014 and there's still no elegant solution to this that I know of, but I like the idea of adding a short pause with setTimeout to your app's init code. If adding a setTimeout call isn't possible, you can also issue window.location.reload() from the Safari console to restart your application with the benefit of full debugging.

1) Inside your OnDeviceReady handler add debugger;
onDeviceReady: function() {
debugger;
// the rest of your device ready code
}
2) Run the application via xcode or cmdline.
3) Attach the debugger via Safari->Develop->Simulator->Appname -> index file
4) Open the console view of safari and enter:
Window.location = "";
5) The app will reload and the debugger will attach on the first line of onDeviceReady().
6) Debug as normal.

Related

From iOS Objective-C code and Android Java code to a Codename One PeerComponent

At the page https://www.wowza.com/docs/how-to-build-a-basic-app-with-gocoder-sdk-for-ios there are the following examples:
if (self.goCoder != nil) {
// Associate the U/I view with the SDK camera preview
self.goCoder.cameraView = self.view;
// Start the camera preview
[self.goCoder.cameraPreview startPreview];
}
// Start streaming
[self.goCoder startStreaming:self];
// Stop the broadcast that is currently running
[self.goCoder endStreaming:self];
The equivalent Java code for Android is reported at the page https://www.wowza.com/docs/how-to-build-a-basic-app-with-gocoder-sdk-for-android#start-the-camera-preview, it is:
// Associate the WOWZCameraView defined in the U/I layout with the corresponding class member
goCoderCameraView = (WOWZCameraView) findViewById(R.id.camera_preview);
// Start the camera preview display
if (mPermissionsGranted && goCoderCameraView != null) {
if (goCoderCameraView.isPreviewPaused())
goCoderCameraView.onResume();
else
goCoderCameraView.startPreview();
}
// Start streaming
goCoderBroadcaster.startBroadcast(goCoderBroadcastConfig, this);
// Stop the broadcast that is currently running
goCoderBroadcaster.endBroadcast(this);
The code is self-explaining: the first blocks start a camera preview, the second blocks start a streaming and the third blocks stop it. I want the preview and the streaming inside a Codename One PeerComponent, but I didn't remember / understand how I have to modify both these native code examples to return a PeerComponent to the native interface.
(I tried to read again the developer guide but I'm a bit confused on this point).
Thank you
This is the key line in the iOS instructions:
self.goCoder.cameraView = self.view;
Here you define the view that you need to return to the peer and that we can place. You need to change it from self.view to a view object you create. I think you can just allocate a UIView and assign/return that.
For the Android code instead of using the XML code they use there you can use the WOWZCameraView directly and return that as far as I can tell.

Deleting file from IsolatedStorageFile causes "IsolatedStorageException: Operation not permitted" when lock screen image wants to update

When generating a lock screen image for Windows Phone 8.0 silverlight app, I use the following code:
fileName = Guid.NewGuid() + ".jpg";
using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var isostream = iso.CreateFile(fileName))
{
Extensions.SaveJpeg(bmp, isostream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
isostream.Close();
}
}
This works absolutely fine both when I run the app or via the background task (assuming the lock screen setting is on).
I've recently added code that runs whenever I launch the app to delete previous lock screen images for storage efficiency purposes.
This is the code which is used in App.xaml.cs:
using (var iso = IsolatedStorageFile.GetUserStoreForApplication() )
{
foreach (string file in GetAllFiles("*.jpg", iso))
{
iso.DeleteFile(file);
}
iso.Dispose();
}
The GetAllFiles method was copied from: http://msdn.microsoft.com/en-us/library/zd5e2z84%28v=vs.110%29.aspx.
When debugging this works fine; all lock screen images that were created since the last time the app launched would get successfully deleted. Just to be clear, the only jpg's stored by the app are the lock screen images.
However, the problem is whenever I do include this delete operation, the lock screen image stops updating from that moment onwards. I get this exception whenever any attempt is made to update it:
System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFile.OpenFile(String path, FileMode mode)
...
A few things to keep in mind:
1) whenever the app is launched, the delete operation is run first in App.xaml.cs, whereas the lock screen image gets updated at a later point by the view model (this is for a weather app, so the new lock screen image is created after the weather is returned).
2) the delete operation is only run when the app is actively opened AND the lock screen setting is on; it isn't called at all in the background task.
What is weird is when I do a fresh install of the app, the lock screen setting by default is off. When I turn the lock screen on, the lock screen image gets created successfully. If I close the app and never relaunch it (thereby never calling the delete operation code), the lock screen image never gets updated because the background task runs into the same previously referenced exception.
If I follow the same exact steps but with no delete operation code in App.xaml.cs, the lock screen image gets updated successfully every time.
3) the live tile continues to be updated without any problems, both when the app is launched or in the background task (that it shares with the lock screen).
Any ideas what's going on here, and what I can do to address this?
can you please provide the code snippet for getting image from isolated storage and updating it to lock screen
Usually this exception is thrown when two threads are trying to access the same isolated storage. This can occur only when it is not attached to debugger (in your case). It is tricky to find. I think while the images are deleted, in same moment the image is also getting saved.
The documentation suggests just alternating between two file names like such:
string fileName;
var currentImage = LockScreen.GetImageUri();
if (currentImage.ToString().EndsWith("_A.jpg"))
{
fileName = "LiveLockBackground_B.jpg";
}
else
{
fileName = "LiveLockBackground_A.jpg";
}
var lockImage = string.Format("{0}", fileName);
I use this approach in one of my apps without issue.
If you wish to continue to use the random Guid, then you should check that the file name is not the same as the current lockscreen before trying to delete.
var currentImage = LockScreen.GetImageUri();
using (var iso = IsolatedStorageFile.GetUserStoreForApplication() )
{
foreach (string file in GetAllFiles("*.jpg", iso))
{
if(AreFilesTheSame(currentImage, file) == false)
{
iso.DeleteFile(file);
}
}
}

Allow only one Chromium app instance

I have the Chromium source on Windows 7, and launch my custom app with the --app="..url" switch through a .bat file. How can I prevent users from opening more than one instance of my Chromium app? This includes opening the .exe directly, using the .bat file and by selecting "Chromium" from the jump list menu on the task bar.
If the app is launched with the --app="...url" flag, then the following solution will prevent further "instances" of Chrome being opened. I say "instances" because Chrome doesn't actually create new Chrome base processes. Instead, it opens a new window with a process used for rendering that particular window.
So, when the app is in --app mode, all you need to do is prevent new windows from opening. This can be accomplished by modifying the OpenApplicationWindow() method within the Chromium source code Application_launch class: chrome/browser/ui/extensions/application_launch.cc.
...
OpenApplicationWindow(const AppLaunchParams& params) {
browser = chrome::FindBrowserWithProfile(profile, params.desktop_type);
#endif
WebContents* web_contents;
if (!browser) {
browser = new Browser(browser_params);
web_contents = chrome::AddSelectedTabWithURL(
browser, url, content::PAGE_TRANSITION_AUTO_TOPLEVEL);
web_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
web_contents->GetRenderViewHost()->SyncRendererPrefs();
}
else {
web_contents = browser->tab_strip_model()->GetActiveWebContents();
}
browser->window()->Show();
...
*NOTE: There should be some Windows 8 code in this method already. The idea is to remove the conditions for Windows 8 Metro Mode, so new Windows are always prevented.

WPF webrowser control - flash working only first time

I have a very strange problem on my wpf application.
I use a webbrowser control to display a third-party web page that uses flash to provide some functionality.
On internet explorer 9 and 10 i have a particular behaviour : the first time I open the webbrowser control everything works fine, and the application puts a .SWF file inside my temporary internet files folder. When I close and reopen the webcontrol, the following error arise :
"object does not support property or method 'UpdateTimeLeft'".
If i manually delete the .SWF file inside the temporary folder, close ad reopen the application, everything works fine again.
This is the code that arise the exception :
var swfUrl = "//" + serverName + "/js/tv/FlashTurboLotto3.swf";
var expressSwfUrl = "//" + serverName + "/js/tv/expressInstall.swf";
var flashvars = {};
var params = {wmode:"transparent", allowscriptaccess:"always" };
var attributes = {id:"FlashTurboLotto3", name:"FlashTurboLotto3", align:"top"};
swfobject.embedSWF(
swfUrl,
"flashcontent",
"100%",
"197",
"9.0.0",
expressSwfUrl,
flashvars,
params,
attributes
);
function updateTimeleft(drawID, timeleft)
{
var swf = document.getElementById("FlashTurboLotto3");
swf.updateTimeleft(parseInt(drawID), timeleft);
}
does anyone have an idea of why this appens and how to solve the issue?
Thank in advance.
I found the solution - It is a very particular bug of Flash. Sometimes happens that when the flash application runs in a non-native browser (like, in my case, a webbrowser control in WPF) the javascript fails at retrieving the .swf file from the cache, so the Flash object will not get initialized.
I solved, for now, by forcing to not use the browser cache, simply adding a random value to the .Swf download Url.

Adobe Flex OpenWithDefaultApplication Movie

I am working on an Adobe Air application that I would like to be able to launch a movie using the default application. The code I am trying is:
var file:File = new File;
//currentMovie.ConfiguredPath = 'D:\\Movies\\TestMovie.avi';
file.nativePath = currentMovie.ConfiguredPath;
file.openWithDefaultApplication();
I have also tried this:
//currentMovie.ConfiguredPath = file://D:/Movies/TestMovie.avi'
navigateToURL(newURLRequest(currentMovie.ConfiguredPath));
The first option does nothing. No application opens, no errors, nothing. The second option worked but it launches a separate window, downloads the file to the local user's download directory then opens the file (as long as you click "Open"). This is not exactly the behavior that I was hoping for.

Resources