Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 3    Views: 77

Dkeller
Aspiring developer
Profile
Posts: 153
Reg: Aug 18, 2011
Saint Augustine
3,680
08/15/12 07:51 AM (11 years ago)

Appoxee and BT

Okay, fellow BT-er's, I have a question for you. I have successfully implemented Appoxee into my app for Push Notifications, but I have a question on how to add a feature through some coding. As expected, once a push notification is sent to the device, the app icon shows a badge with the number of messages. Once the app is opened, and on the home screen, there is an envelope icon that is to be touched to open the messages sent by the Appoxee server. My question is: Is there a way to create a badge on the envelope icon when there is a new message? I know there is a way to do it, but I am not a fluent coder and need help with the implementation. Thanks in advance!!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/16/12 03:00 AM (11 years ago)
Hi in Saint Augustine, there is always a way! LOL. "A badge on the envelope icon when there is a new message." I haven't used Appoxee but it shouldn't matter. Where is this envelope icon? In one of the app's tabs? On a screen somewhere? Laughing a bit..where the heck is this thing, can't be too tough. Oh, also, iOR or Android?
 
Dkeller
Aspiring developer
Profile
Posts: 153
Reg: Aug 18, 2011
Saint Augustine
3,680
like
08/16/12 06:27 AM (11 years ago)
Wow, @David is really answering MY question? Too cool!!! I am working in iOS. The envelope icon is in the navigation bar on the tabbed home screen of the app (opposite from the refresh button). I'm really just looking for this little icon to have some sort of indicator to let people know that there is something to look at when there is a new message pushed to them. Appoxee uses a push&message system that sends the user a push message letting them know there is a message awaiting them withing the app. Inside the app, the "envelope icon" leads the user to an Inbox of messages that I have pushed out. There are indicators on the messages if they have been read or not. I just want the "envelope icon" to show differently if there is an unread message. I'm pretty sure it's a simple fix (replacing the icon with a modified one when there is a new message), but I do not know the logic behind the code to implement it. Any help would be appreciated. Thanks again @David for responding!!!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/17/12 12:45 AM (11 years ago)
Ah...got it, makes perfect sense. Lets see if we can engineer this together...some background... When the app first loads (after a refresh or for the first time), it creates the tabbed layout along the bottom and sets the home screen for each tab, the tabs image, and the tabs text. This means it's this process that assigns the envelope icon to the tab. In this case, the 1st tab on the left. Most folks think that an additional image is necessary (an envelope with a badge on it), it's NOT. iOS is capable of setting a badge on a tab for you. Whoo hoo, this make it much easier and far more "pro" because you want the badge to look like all the other standard iOS alert badges (a red circle with a number in it). First, do this as a test: In your Xcode project, find the folder named BT_config and open up you app delegates.m file. It will be named [your app name]_appDelegate.m This is the file that sets up the layout of the app when it launches. Layout meaning each tab and all sorts of other goodies. A method called configureEnvironmentUsingAppData that begins on line 252 does tons of heavy lifting when setting up the app. You'll notice on line 278 it does: [self.rootApp buildInterface]; In english, this is "hey applocation, go build your interface and return back here when you're done." So, it's actually the "application class" that literally builds the parts to the interface. Off we go to the BT_application.m file to figure this out. Open the BT_Core folder and find the BT_application.m file, open that baby up...scroll down to line 345 and fine the start of this method: buildInterface, it looks like this: -(void)buildInterface{ This is the method that the app delegate "fired" and it's this method you'll need to try to figure out. I'll help you... Scroll down to line 415 where it does "hey app, do you have more than 0 tabs" and "do all of this if you do." Cool, our apps has tabs so this code runs. Look at line 424 and find: rootTabBarController = [[BT_rotatingTabBarController alloc] init]; The "rootTabBarController" property is an instance of the BT_rotatingTabBarController class. Huh, what the heck does that mean? ! It means we can access our "rootTabController" anywhere in our project and ask it to change the badge icon for any of it's tabs. Remember, the rootTabBarController "understands" that it has some tabs with icons, titles, etc. This means we will need to "tell the rootTabBarController to update it's badge" at the right time. In this case, this time will be when the app learns that it has a new message from Appoxee. This is where you know more than me. I'll guess that all your Appoxee logic is back in that app delegate.m file we started with. Sigh...lets go back there! Back in your app delegate.m file, you probably have some logic in the didFinishLaunchingWithOptions method. I'm guessing this because most folks put code in this method to handle all the push notification logic. If this is the case in your app, it's in here (in this didFinishLaunchingWithOptions method) that you'll want to set your tabs badges. BUT, and this is super important, you CAN'T set or change a tab badge until AFTER the tabs are created. This means you can't do anything like this "at the top" of the didFinishLaunchingWithOptions method. You need to wait until the tabs are setup. In other words, you need to add your "badge altering code" to the didFinishLaunchingWithOptions method AFTER the interface is setup. But wait, the didFinishLaunchingWithOptions doesn't setup the interface, the configureEnvironmentUsingAppData does. Wowza, getting complicated. Hope you're following! So, back to the configureEnvironmentUsingAppData method on line 252. Remember, this is the method that in turn does the [self.rootApp buildInterface]; on line 278. This is where you want to alter the badge, JUST AFTER line 278 (after the tabs are setup). You're probably thinking, "why didn't you just tell me that in the first place?" !!! Answer, because I'm digging through this as I type. Too funny. Try this on line 280 or so (make space just after the [self.rootApp buildInterface] method call: [[[[[self.rootApp rootTabBarController] tabBar] items] objectAtIndex:0] setBadgeValue:@"1"]; That's a lot of square brackets, lets hope we didn't use them all up!!! Laughing. That line should set the badge on the "first tab" (the tabs start at 0, 1, 2, ...) to the number 1. Compile, run, see if it works. If it does, then you know where to put your logic. The next challenge you'll have is learning how to reset / remove this badge after the user sees what you want them to see. Hint: In your view controller (plugin) that shows the messages, access the rootTabBarController and do the same thing but remove the badge. I'm sure you can take it from here.... Lastly, your remark: "Wow, @David is really answering MY question?" is neat. To think that I'm any different from anyone else helping? I enjoy helping in the forums more than anything else I do. I sincerely wish I could literally type comments all day long and help folks get their apps created in ways they may not think their capable of (yet, until they learn). However, it's very very tough to balance all the things I'm balancing recently. But, your remark made me smile and I appreciate the idea that you think it's neat that I'm helping. Kind of a little pay-off for me :-) Go kick this things ass, repost if you get stuck.
 

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.