objective c - NSTimer crashing my application -


so have application uses nstimer. problem when nstimer runs, application crash exc_bad_access. started objective-c don't know how debug it. if thought call -(void)login{} [self login]; application work. code:
.h

@interface dj_wappdelegate : nsobject {    nstimer *logintimer;     }      -(void)login;        @end 

.m

- (void)applicationdidfinishlaunching:(nsnotification *)anotification {     [self login];   // works     logintimer = [nstimer scheduledtimerwithtimeinterval:5.0 target:self selector:@selector(login) userinfo:nil repeats:yes];   // fails }  - (void)login {     nslog(@"logging in...");      // if comment out these 2 lines works nstimer!?... (i've have more code below)     nsurl *loginconn = [nsurl urlwithstring:[nsstring stringwithformat:@"some-website.com"]];        nsinteger loginreturn = [[nsstring stringwithcontentsofurl:loginconn encoding:nsasciistringencoding error:nil] intvalue];     // when "loginreturn" return "ok" timer (logintimer) stopped with: [logintimer invalidate];     // more code below... (which works!) } 


so problem nsurl think. helping.

edit 1: here's crash stack:

    eexception type:  exc_bad_access (sigbus) exception codes: kern_protection_failure @ 0x0000000000000020 crashed thread:  0  dispatch queue: com.apple.main-thread  application specific information: objc_msgsend() selector name: respondstoselector:   thread 0 crashed:  dispatch queue: com.apple.main-thread 0   libobjc.a.dylib                 0x9603bed7 objc_msgsend + 23 1   com.apple.corefoundation        0x922ed5f2 _cfstringappendformatandargumentsaux + 3138 2   com.apple.corefoundation        0x922ec979 _cfstringcreatewithformatandargumentsaux + 105 3   com.apple.foundation            0x9656ebfb -[nsplaceholderstring initwithformat:locale:arguments:] + 163 4   com.apple.foundation            0x9656eaae +[nsstring stringwithformat:] + 88 5   com.who.dj-w                0x00001d56 -[dj_wappdelegate login] + 116 (dj_wappdelegate.m:108) 6   com.apple.foundation            0x965b08d4 __nsfiretimer + 141 7   com.apple.corefoundation        0x922ffadb __cfrunlooprun + 8059 8   com.apple.corefoundation        0x922fd464 cfrunlooprunspecific + 452 9   com.apple.corefoundation        0x922fd291 cfrunloopruninmode + 97 10  com.apple.hitoolbox             0x91646e04 runcurrenteventloopinmode + 392 11  com.apple.hitoolbox             0x91646bb9 receivenexteventcommon + 354 12  com.apple.hitoolbox             0x91646a3e blockuntilnexteventmatchinglistinmode + 81 13  com.apple.appkit                0x9265378d _dpsnextevent + 847 14  com.apple.appkit                0x92652fce -[nsapplication nexteventmatchingmask:untildate:inmode:dequeue:] + 156 15  com.apple.appkit                0x92615247 -[nsapplication run] + 821 16  com.apple.appkit                0x9260d2d9 nsapplicationmain + 574 17  com.who.dj-w                0x00001c92 start + 54 

hope helps... find error

edit 2:
zombie mode on this: *** -[cfstring respondstoselector:]: message sent deallocated instance 0x46d550 hope helps.

edit 3:
ball: here original url (took away domain here) /djw/work.php?user=iblackbirdi&udid=00000000-0000-1000-80005&key=660e5744e&cmd=slocau&type=get

there several problems here:

  1. djwlog class method should call on class not instance this: [[self class] djwlog:@"foo bar"]

  2. the urlfromstring: method needs string contain valid url specified rfc 1808. along lines of [nsurl urlfromstring:@"http://example.com/foo"]

  3. stringwithcontentsofurl:url… syncornous method. unless have code running in separate thread should not use this. @ nsurlconnection class asynchronously load data url. using synchronized calls bad idea. always.

  4. intvalue returns signed integer. nsinteger use integervalue. if use stringwithcontentsofurl make sure check if it's result nil before calling integervalue otherwise might result of 0 if url call failed or did not return data. real parser api calling idea in case.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -