• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: widget plugin crashed when i use thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: widget plugin crashed when i use thread


  • Subject: Re: widget plugin crashed when i use thread
  • From: Sam Tseng <email@hidden>
  • Date: Tue, 12 Jan 2010 22:06:58 +0800

sorry, i have another question about "WebScriptObject callWebScriptMethod" :

i used **[webScriptObject callWebScriptMethod:@"_updateInfo"
withArguments:args];** to call javascript _updateInfo function. it can
be called with correct parameters. however, it complains
document.getElementById("f_name") is null. i don't know how to access
the html element after called from widget plugin.

following is in javascript :
function _updateInfo(currentTrack) {
    if (currentTrack != "NOT RUNNING" && currentTrack != "NOT PLAYING") {
        var info = currentTrack.split("|");
        song = info[0];
        album = info[1];
        artist = info[2];
        //document.getElementById("f_name").innerHTML = song;
        //document.getElementById("f_album_artist").innerHTML = album
+ " - " + artist;
    } else {
        // idle();
    }
}

following is part of codes in xcode :
- (void) windowScriptObjectAvailable:(WebScriptObject *) scriptObj
{
	[scriptObj setValue:self forKey:@"pTunes"];
	webScriptObject = scriptObj;
	[webScriptObject retain];
}
(omit)
NSArray* args = [NSArray arrayWithObjects:
                          trackInfo,
                          nil];
[webScriptObject callWebScriptMethod:@"_updateInfo" withArguments:args];

i've read ADC documentation, but i still can't figure it out. please
teach me. thank you in advance.

best, sam

On Tue, Jan 12, 2010 at 9:51 PM, Sam Tseng <email@hidden> wrote:
> hi,
>
> i would like to implement a widget plugin to detect iTunes current
> artist and current album call back to widget. i ran my widget plugin
> in dashcode without crashing. however, i deployed the widget into
> dashboard, it crashed all the time. following is part of my codes,
> could any one give me hints to tell me which part may cause this
> problem. thank you for your help. :)
>
> - (id) initWithWebView:(WebView*)webView
> {
>        self = [super init];
>        iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
>        pTunesRun = TRUE;
>        previousdatabaseID = @"";
>        [NSThread detachNewThreadSelector:@selector(checkiTunesStatus)
> toTarget:self withObject:nil];
>        return self;
> }
>
> - (void) checkiTunesStatus
> {
>        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
>        while (pTunesRun) {
>                if ([iTunes isRunning]) {
>                        if ([iTunes playerState] == iTunesEPlSPaused || [iTunes
> playerState] == iTunesEPlSStopped) {
>                                trackInfo = [NSString stringWithFormat: @"%s", "NOT PLAYING"];
>                        } else {
>                                if (!iTunes.currentTrack.artist || !iTunes.currentTrack.album)
>                                        trackInfo = [NSString stringWithFormat: @"%@|NULL|NULL",
> iTunes.currentTrack.name];
>                                else if (!iTunes.currentTrack.artist)
>                                        trackInfo = [NSString stringWithFormat: @"%@|%@|NULL",
> iTunes.currentTrack.name, iTunes.currentTrack.album];
>                                else if (!iTunes.currentTrack.album)
>                                        trackInfo = [NSString stringWithFormat: @"%@|NULL|%@",
> iTunes.currentTrack.name, iTunes.currentTrack.artist];
>                                else
>                                        trackInfo = [NSString stringWithFormat: @"%@|%@|%@",
> iTunes.currentTrack.name, iTunes.currentTrack.album,
> iTunes.currentTrack.artist];
>                        }
>                        currentdatabaseID = [NSString stringWithFormat: @"%d",
> iTunes.currentTrack.databaseID];
>                } else {
>                        trackInfo = [NSString stringWithFormat: @"%s", "NOT RUNNING"];
>                }
>                if (autoRefresh) {
>                        if (![previousdatabaseID isEqualToString: currentdatabaseID]) {
>                                NSArray* args = [NSArray arrayWithObjects:
>                                                                 trackInfo,
>                                                                 nil];
>                                [webScriptObject callWebScriptMethod:@"_updateInfo" withArguments:args];
>                                previousdatabaseID = [NSString stringWithFormat: @"%@", currentdatabaseID];
>                        }
>                }
>                [NSThread sleepForTimeInterval:1.0];
>        }
>        [pool release];
>        [NSThread release];
> }
>
> best, sam
>



--
Sam Tseng
Academia Sinica
Institute of Astronomy and Astrophysics
Tel: +886-2-2366-5392
Fax: +886-2-2367-7849
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >widget plugin crashed when i use thread (From: Sam Tseng <email@hidden>)

  • Prev by Date: appController class in InterfaceBuilder
  • Next by Date: Re: A password strength checker
  • Previous by thread: widget plugin crashed when i use thread
  • Next by thread: appController class in InterfaceBuilder
  • Index(es):
    • Date
    • Thread