Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 14    Views: 123

mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
11/25/13 06:11 PM (11 years ago)

Calling the Refresh Config function

Hi guys, Working on calling the "refresh" method/action in a custom plugin. @Smug's helped me a lot with this but we're both scratching our heads on why it crashes the app. The code below is this: APPNAME_appDelegate *appDelegate = [[APPNAME_appDelegate alloc]init]; [appDelegate refreshAppData]; And after it's called, it crashes and shows this in the log: https://www.dropbox.com/s/272fi2emyxk6x4w/Screen%20Shot%202013-11-24%20at%207.58.22%20AM.png Any help would be awesome, thanks so much guys. David https://buzztouchmods.com/market
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
11/25/13 07:11 PM (11 years ago)
First thing I notice is you're creating a new instance of the appDelegate rather than referencing the shared one for your app
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
11/25/13 08:39 PM (11 years ago)
Yup we had to do that to get rid of the error, if you just do: [self refreshAppData]; you get this: https://www.dropbox.com/s/j4mxy5s7tx3c7b2/Screen%20Shot%202013-11-25%20at%207.35.59%20PM.png David https://buzztouchmods.com/market
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
11/25/13 08:41 PM (11 years ago)
try something like this? //appDelegate APPNAME_appDelegate *appDelegate = (APPNAME_appDelegate *)[[UIApplication sharedApplication] delegate]; [appDelegate refreshAppData];
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
11/25/13 08:47 PM (11 years ago)
Assuming you want me to uncomment the top one, and update the delegate names right? Got this: https://www.dropbox.com/s/qgyymrj67xxlu5v/Screen%20Shot%202013-11-25%20at%207.45.40%20PM.png Thanks Chris. David https://buzztouchmods.com/market
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
11/25/13 08:49 PM (11 years ago)
sorry - there should be a line break after: //appDelegate so that the appDelegate code looks like: shaketest_appDelegate *appDelegate = (shaketest_appDelegate *)[[UIApplication sharedApplication] delegate];
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
11/25/13 08:54 PM (11 years ago)
It worked! and even better then I had hoped! Thanks a ton Chris, is there any easy explanation to how it was solved compared to what we tried initially (or why it crashed for that matter)? Thanks so much again. David https://buzztouchmods.com/market
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
11/25/13 09:07 PM (11 years ago)
yep - so the "appDelegate" is meant to be an object shared across the entire app. Essentially any screen/plugin can reference it and access it's properties and methods. The only trick is that you need to access the instance originally initiated when the app loads. When you call a command like: className *theObject = [[className alloc]init]; you are initiating a new object of that class. Thus, when you do this to the appDelegate class, you are not referencing the object that was created when the app loaded, instead you are referencing a new object entirely. The method you're trying to call (refreshAppData), uses properties of the object that cannot be nil (or it will crash). And those properties are called during the app launch phase. Since you are creating a new object during run-time, it never sets those properties and thus crashes. Hope that makes sense.
 
WolfTimJ
buzztouch Evangelist
Profile
Posts: 810
Reg: Feb 20, 2011
Rockwall, TX
17,400
like
11/25/13 09:17 PM (11 years ago)
molecules
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
11/25/13 09:55 PM (11 years ago)
@Chris, I get it a little, I'll get it more as I keep learning, I'll look back at your post. @Smug will be able to dissect it better and translate it for me too, thanks as always. @WolfTimJ lol, tell me about it! David https://buzztouchmods.com/market
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
11/25/13 10:18 PM (11 years ago)
My recommendation: pick up a book on iOS or objective-c programming and work your way through the first half of the book. Skim what you can and do some of the exercises. Then look back at my post and be amazed at how simple it sounds. :)
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
11/25/13 11:20 PM (11 years ago)
Hah! I knew it would be something simple. Simple or not, it was driving me crazy, lol! Nice catch Chris! :) Cheers! -- Smug
 
peterj
Apple Fan
Profile
Posts: 113
Reg: Jun 19, 2011
location unknow...
6,630
like
11/26/13 09:07 AM (11 years ago)
Speaking of how simple it sounds...I had my minor epiphany just last night. I've been doing Buzztouch for a couple of years, and just recently reading some programming books and articles, reading the BT code comments, trying to figure it all out. For whatever reason, my epiphany was kicked off watching a lecture from iTunes University - Standford's CS106A "Programming Methodology". The lecture and the reader for that class gave me a nice a-ha moment. Still consider myself a novice, but so far watching along with that class has been great.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
11/26/13 01:53 PM (11 years ago)
Great! - care to share what the epiphany was?
 
peterj
Apple Fan
Profile
Posts: 113
Reg: Jun 19, 2011
location unknow...
6,630
like
12/02/13 08:39 AM (11 years ago)
Oh, it was nothing spectacular, just a nice a-ha moment for an amateur...the abstract nature of object code has always felt foggy for me, and I think my mind has been making it more complicated than it really is. I've read a dozen people's attempts to explain it, but something about the Stanford course reader, when it said how object code separates the state of the object from the behavior, and changing its state with messages...something about reading that made me think, "ok, is it really that simple?"...objects and messages in between them that change things...it just really helped me see it as a much simpler thing than my mind was making it out to be. And it's turned me from someone who can say, "ok i'll look around in the code a bit to see if i can see how it's working", and maybe even making a change to fix it the way I want, instead of saying, "boy I hope SmugWimp gives me some code to paste in!" :)
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.