Discussion Forums  >  Self Hosted Control Panels

Replies: 15    Views: 454

andydahl
Aspiring developer
Profile
Posts: 209
Reg: Jul 20, 2011
Villa Grove
4,540
07/28/12 10:39 AM (13 years ago)

Parse push notifications - When app is opened

Just discovered this, so I thought I'd share. Normally (at least in my builds with Parse), if the app is open when the push hits the device, it's lost and not shown. By adding the code below to your .m file, it will 'catch' the push and display it at an alert on the phone: - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; } I placed it under the '//load data' in my .m file and it seems to work. Still working on getting the number badge to show on the icon and I'd really like to figure out how to show the push notifications as a list within the app. Regards, Andy
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
07/28/12 11:03 AM (13 years ago)
Andy, Awesome share - thank you so much! David buzztouchmods.com
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/28/12 03:50 PM (13 years ago)
Freaking awesome!!! Thank you!!!!!!!!
 
XboxMods
buzztouch Evangelist
Profile
Posts: 718
Reg: Oct 28, 2011
location unknow...
12,080
like
07/28/12 06:54 PM (13 years ago)
Thanks alot for sharing! Raoul
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
07/29/12 08:30 AM (13 years ago)
Hi andydahl can you show a screen grab of where you placed the code? As I keep getting errors when I place it under the '//load data'.
 
andydahl
Aspiring developer
Profile
Posts: 209
Reg: Jul 20, 2011
Villa Grove
4,540
like
07/29/12 09:40 AM (13 years ago)
Sure. Here's where I put it: https://www.dropbox.com/s/yutbx4e40oungd3/Xcode.png I'm using BT 2.0
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/29/12 09:45 AM (13 years ago)
and on BTv1.5? Thanks
 
andydahl
Aspiring developer
Profile
Posts: 209
Reg: Jul 20, 2011
Villa Grove
4,540
like
07/29/12 09:47 AM (13 years ago)
Currently not using v1.5 so I really have no idea. Sorry!
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/29/12 10:18 AM (13 years ago)
Not a big deal. Thank you
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
07/29/12 12:45 PM (13 years ago)
Hi Isills81 your guide for integrating Parse, was it for BT 1.5? Also for iOS, in the Parse control panel do you have the apps installation ID displayed in the data browser or is yours blank, as mine is blank. Still been unable to get my Parse going on my iOS apps for BT 1.5.
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/29/12 01:56 PM (13 years ago)
BTv1.5 Have you watched the tutorial?
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
08/03/12 09:17 AM (13 years ago)
I just got Parse working in my 2.0 Self Hosted Andy - that code chunk you posted. I think Parse added this to their tutorial/documentation recently. I was trying to use the code/framework Isillis81 posted in his great tutorial (really man, this thing is great. clear/concise, excellent stuff!!). His code worked great on the simulator - but the app would not install on my 3GS. I dug into the Parse documentation and grabbed the latest Framework and added it. Here's the code snippet I used. You can see that it has that same code you posted in the -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [PFPush storeDeviceToken:deviceToken]; [PFPush subscribeToChannelInBackground:@"" block:^(BOOL succeeded, NSError *error) { if (succeeded) NSLog(@"Successfully subscribed to broadcast channel!"); else NSLog(@"Failed to subscribe to broadcast channel; Error: %@",error); }]; } -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Failed to register for push, %@",error); } -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; PFObject *testObject = [PFObject objectWithClassName:@"TestObject"]; [testObject setObject:@"bar" forKey:@"foo"]; [testObject save]; } If I try to put your code below my //loaddata statement - i get Duplicate Declaration errors. So 3 different code samples here to work with. I'm getting the Push notification when I'm in the app. I'm getting it if the app is closed. I'm getting it if I'm using another app. If the device is locked and in hibernation - I get the push as soon as i wake it. I hear the alert while i'm putting in my passcode. I do like how the notice is not displayed I know I have apps that send notices when it's in hibernation - but i think those use LOCAL Push Notification Services...? and I think those show the message even in lock mode. New stuff for me to play with, already looking at that Parse Image Uploader project.... big thanks to isillis again here for getting me started with Parse, you eased that learning curve quite a bit.
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
08/03/12 10:32 AM (13 years ago)
@ATRAIN53 thank you but it seems like I didn't help... I don't understand... I am on BTv1.5 and had no problems. I assume that is because we are talking about BTv1.5 vs BTv2.0? What iOS was your iPhone 3GS on also?
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
08/03/12 11:37 AM (13 years ago)
I test on a 3GS with iOS 4.2.1 Believe me your vid was VERY helpful. I'd still be reading their documentation probably... Bottom line is the zip you had with the framework didn't work for me on 2.0 Self Hosted. I tried it first. So I grabbed their framework and used their code samples - but used your instructions.
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
08/03/12 07:05 PM (13 years ago)
So this works in BTv1.5 the same....very nice. Wonder how I can alter the color scheme. Thank you for this post. as @ATRAIN said I'm getting the Push notification when I'm in the app. I'm getting it if the app is closed. I'm getting it if I'm using another app. all in BTv1.5 following this and my tutorial on Youtube @macordie81 As it says above: - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; } I placed it under the '//load data' in my .m file and //it seems to work// it works 100%
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
08/10/12 11:11 AM (13 years ago)
How could I use this code to create the in-app notification but also include a button and then a response to that button? Like when a Voicemail is left and you are given the choice to listen to it. Thanks
 

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.