Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 45    Views: 558

Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
05/03/12 06:08 AM (13 years ago)

Need Help Adding Push Notification Using Parse

Hi I am trying to add Push Notification to my app using Parse but I am stuck on where to add the final bit of code, which stats: Then paste the following inside the application:didFinishLaunchingWithOptions: function: [Parse setApplicationId:@"WjO1trwyesGqcB4m69ZkRZrLrDQNhZHecBtTtnup" clientKey:@"nM3risspRanGJXzmDpFMpMbc6EMWKrc0wFjo8zGr"]; I have no idea where about's on my 'appDelegent.m' file this code should be placed. Can someone help!
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 06:17 AM (13 years ago)
OK. The first bit of code in the appdelegate.m file after 'didFinishLaunchingWithOptions' goes after this line: //init the allowed input characters string. ONLY these characters will be allowed in input fields. allowedInputCharacters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.@!$"; [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge| UIRemoteNotificationTypeAlert| UIRemoteNotificationTypeSound]; The code you mention above goes second to bottom in your main.m file. You follow?
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 06:29 AM (13 years ago)
completely lost me!
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 06:33 AM (13 years ago)
sorry, what do you mean by The code you mention above goes second to bottom in your main.m file. Second to bottom is where I am confused. This is for adding push using Pars.com?
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 06:35 AM (13 years ago)
Driving. Give me 5 to get to office
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 06:57 AM (13 years ago)
thanks for the help
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 07:06 AM (13 years ago)
OK. Parse, yes, I hear you. Are you sure the lines of code you mention above do not go into the main.m file? I'm sure you enter it as the second to last piece of code in that file. The code that goes after didfinishlaunching is this: [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge| UIRemoteNotificationTypeAlert| UIRemoteNotificationTypeSound];
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 07:08 AM (13 years ago)
Hi yes the code needs to be added to the .m file. I have added your bit of code but the code I need to add from them is where I am stuck. Sorry the code you gave me which file should I be adding this to .h or .m?
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 07:11 AM (13 years ago)
The code above in my last post goes in your main app delegate.m The other code goes in a different file altogether, the file called main.m
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 07:17 AM (13 years ago)
Hi Parse say that the code they supplied goes in the AppDelegent.m file inside the application:didFinishLaunchingWithOptions: function: [Parse setApplicationId:@"WjO1trwyesGqcB4m69ZkRZrLrDQNhZHecBtTtnup" clientKey:@"nM3risspRanGJXzmDpFMpMbc6EMWKrc0wFjo8zGr"]; I'm lost!
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 07:25 AM (13 years ago)
Tough doing this on iPhone without Xcode next to me. If you can hold on and if nobody next to a computer jumps in I'll send you screen shuts of my code and the files when I get home.
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 07:26 AM (13 years ago)
I have it working in several apps but going from memory now. If you're in London I'm 5 hrs behind you so it'll be 10pm at earliest until I get to my Mac.
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 07:27 AM (13 years ago)
Ps. The Parse guide is 100% correct, don't let my memory lead you astray.
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 07:31 AM (13 years ago)
I appreciate all the help.
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 08:31 AM (13 years ago)
would you have any idea where this code should go: Next, your app needs to take the device token that Apple gives it and pass it over to Parse. Insert the following code into your main app delegate: - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { // Tell Parse about the device token. [PFPush storeDeviceToken:newDeviceToken]; // Subscribe to the global broadcast channel. [PFPush subscribeToChannelInBackground:@""]; } Again I have no idea where to put it.
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 08:38 AM (13 years ago)
I can tell you where everything goes but not without being in front on my laptop mate. Will shout back later buddy.
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 08:40 AM (13 years ago)
Sorry, i look forward to hearing from you later.
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 08:45 AM (13 years ago)
Your cool. You'll be pushing soon, stuck with it in meantime.
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 08:54 AM (13 years ago)
Sorry, i look forward to hearing from you later.
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
05/03/12 11:29 AM (13 years ago)
Here's what I have in my appdelegate.m file: ---------------------------------------- /* didFinishLaunchingWithOptions this method fires when the application first launches. This is different than when it becomes the active application in a multi-tasking environment */ -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ //your application specific code //set the configuration file name configurationFileName = @"BT_config.txt"; //show debug in output window? showDebugInfo = TRUE; //init the allowed input characters string. ONLY these characters will be allowed in input fields. allowedInputCharacters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.@!$"; [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge| UIRemoteNotificationTypeAlert| UIRemoteNotificationTypeSound]; [Parse setApplicationId:@"REPLACE WITH YOU ID #" clientKey:@"REPLACE WITH YOUR CLIENT KEY"]; ------------------------------------------------------ and then right below the whole didfinishlaunchingwithoptions I have this: ---------------------------------------------------------- - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { // Tell Parse about the device token. [PFPush storeDeviceToken:newDeviceToken]; // Subscribe to the global broadcast channel. [PFPush subscribeToChannelInBackground:@""]; } /* loadAppData method, where is the app's configuration data? ------------------------------------------------------------------------- a) If a cached version of the app's configuration data is available, use that (then check for updates) b) If no cached version is available, use the data in the bundle (then check for updates) c) If no cached version is available, and no dataURL is provided in the bundle config file, use the bundle config data. */ -(void)loadAppData{ [BT_debugger showIt:self:[NSString stringWithFormat:@"refreshAppData%@", @""]]; //set the saveAsFileName and the modified file name (only used if configuration data is pulled from a remote server self.saveAsFileName = @"cachedAppConfig.txt"; self.modifiedFileName = @"appModified.txt"; self.configData = @""; hope this helps!
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
05/03/12 11:32 AM (13 years ago)
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 11:38 AM (13 years ago)
Hi Mutzy you are a star, this really helps, I will follow your install and let you know how I do. Again thanks for your help.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
05/03/12 01:15 PM (13 years ago)
not much help but following along here as i've been tinkering with parse as well unsucessfully so far..... so you're helping more than one person here MacApple....
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 01:17 PM (13 years ago)
OK gents. What I can possibly do to save you all some time is zip up a simple app with Parse working and email it to you both and then you can compare side to side, cool? Cool. Be back at laptop in hour or so.
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/03/12 03:50 PM (13 years ago)
that sounds cool to me.
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 03:51 PM (13 years ago)
Drop me your email and you'll have it in 5 mins. Cool? Cool.
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 04:25 PM (13 years ago)
You have mail Dragon007. Let me know, keep me posted etc
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/03/12 05:48 PM (13 years ago)
ATRAIN53 Email me and I'll send you some help!
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
05/04/12 05:34 AM (13 years ago)
Hi guys i'm still having a few issues integrating the push notification from Parse and I keep getting this errors in Xcode, does anyone know what it means and how I can possibly fix: Undefined symbols for architecture armv7: "_SecItemAdd", referenced from: +[PFInternalUtils saveToKeychain:data:] in Parse(PFInternalUtils.o) "_kSecMatchLimitOne", referenced from: +[PFInternalUtils loadFromKeychain:] in Parse(PFInternalUtils.o) "_kSecAttrAccessibleAfterFirstUnlock", referenced from: +[PFInternalUtils getKeychainQuery:] in Parse(PFInternalUtils.o) "_kSecValueData", referenced from: +[PFInternalUtils saveToKeychain:data:] in Parse(PFInternalUtils.o) "_SecItemDelete", referenced from: +[PFInternalUtils saveToKeychain:data:] in Parse(PFInternalUtils.o) +[PFInternalUtils deleteFromKeychain:] in Parse(PFInternalUtils.o) "_kSecClassGenericPassword", referenced from: +[PFInternalUtils getKeychainQuery:] in Parse(PFInternalUtils.o) "_SecItemCopyMatching", referenced from: +[PFInternalUtils loadFromKeychain:] in Parse(PFInternalUtils.o) "_kSecAttrAccessible", referenced from: +[PFInternalUtils getKeychainQuery:] in Parse(PFInternalUtils.o) "_kSecClass", referenced from: +[PFInternalUtils getKeychainQuery:] in Parse(PFInternalUtils.o) "_kSecAttrService", referenced from: +[PFInternalUtils getKeychainQuery:] in Parse(PFInternalUtils.o) "_kSecReturnData", referenced from: +[PFInternalUtils loadFromKeychain:] in Parse(PFInternalUtils.o) "_kSecMatchLimit", referenced from: +[PFInternalUtils loadFromKeychain:] in Parse(PFInternalUtils.o) "_kSecAttrAccount", referenced from: +[PFInternalUtils getKeychainQuery:] in Parse(PFInternalUtils.o) "_AudioServicesPlaySystemSound", referenced from: +[PFPush handlePush:] in Parse(PFPush.o) "_kCFStreamPropertyHTTPAttemptPersistentConnection", referenced from: -[PFHTTPCommand scheduleInCurrentThread:] in Parse(PFHTTPCommand.o) "_kCFStreamPropertyFTPAttemptPersistentConnection", referenced from: -[PFHTTPCommand scheduleInCurrentThread:] in Parse(PFHTTPCommand.o) "_AudioServicesCreateSystemSoundID", referenced from: +[PFPush handlePush:] in Parse(PFPush.o) ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
05/04/12 07:39 AM (13 years ago)
thanks mac - being able to look at a small project with it working would be a big help. i'm not implementing this for a few weeks, but if you can send that code/project along when you have time, i'd appreciate it. send it here: skompdev @ skomp . net mutzy - that was VERY helpful as well! glad to see you've got it working!
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
05/11/12 11:20 AM (13 years ago)
I've also been trying to implement Parse push in my v2.0 ios app. I find adding code into my programms a bit of a struggle, which is why I love buzztouch. I decided to havea go and followed the instructions in this thread and with some success - I followed all the guidance above, added all the lines of code and my app still compiled and runs without errors, which is good. The bad news is that push notifications don't work. My app doesn't even ask permission to allow push notifications. MacApple, if you have a test app that works, would you mind sharing it with me too pleae? I'd love to find out where I'm going wrong.
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/11/12 11:23 AM (13 years ago)
Guys send me a DM and we can take care if this. Peace and happy Friday!
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
05/11/12 01:27 PM (13 years ago)
Thanks MacApple - DM has been sent!
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
05/15/12 11:02 AM (13 years ago)
It is all to easy to make a simple mistake that stops push working, but I finally made it! Just to say a big thanks to MacApple and everyone else who posted here, it all helped me get Parse going.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
05/15/12 02:20 PM (13 years ago)
It is all to easy to make a simple mistake that stops push working, but I finally made it! Just to say a big thanks to MacApple and everyone else who posted here, it all helped me get Parse going.
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/15/12 02:33 PM (13 years ago)
Nice one. Piece of cake eh?
 
aquila198
buzztouch Evangelist
Profile
Posts: 473
Reg: Jul 22, 2011
location unknow...
10,330
like
05/31/12 10:55 AM (13 years ago)
Ahoy Matey - I'm still on my parse quest. In comparing this thread with the guide (https://parse.com/tutorials/ios-push-notifications) Two pieces of code in the tutorial are not mentioned above: QUESTION 1: (from guide) >>> If the registration is successful, the above method will execute the callback method [application:didRegisterForRemoteNotificationsWithDeviceToken:] in the application delegate. We will need to implement this method and use it to inform Parse about this new device. >>> ***WHERE DOES THE CODE BELOW GO? DOES IT REPLACE SOMETHING?**** - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { [PFPush storeDeviceToken:newDeviceToken]; // Send parse the device token // Subscribe this user to the broadcast channel, "" [PFPush subscribeToChannelInBackground:@"" block:^(BOOL succeeded, NSError *error) { if (succeeded) { NSLog(@"Successfully subscribed to the broadcast channel."); } else { NSLog(@"Failed to subscribe to the broadcast channel."); } }]; } QUESTION 2: (WHERE DOES THE CODE BELOW GO?): - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; }
 
aquila198
buzztouch Evangelist
Profile
Posts: 473
Reg: Jul 22, 2011
location unknow...
10,330
like
05/31/12 11:18 AM (13 years ago)
I think I got it working under the hood. I put the following code under didFinishlaunching.... - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { [PFPush storeDeviceToken:newDeviceToken]; // Send parse the device token // Subscribe this user to the broadcast channel, "" [PFPush subscribeToChannelInBackground:@"" block:^(BOOL succeeded, NSError *error) { if (succeeded) { NSLog(@"Successfully subscribed to the broadcast channel."); } else { NSLog(@"Failed to subscribe to the broadcast channel."); } }]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; } -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ ......now it's off to Production Cert time...oh the joy
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
05/31/12 11:30 AM (13 years ago)
Not at laptop but that sounds right.
 
aquila198
buzztouch Evangelist
Profile
Posts: 473
Reg: Jul 22, 2011
location unknow...
10,330
like
05/31/12 11:53 AM (13 years ago)
Thanks buddy - When you are replacing the Development Cert with the Production Cert ID, do you also need to update the Development Provisioning Profile? It's slightly unclear on the Parse video about this part of the process. \It states, "once you are ready to put your app live, you will need to revisit and configure the app ID for Production."
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
05/31/12 12:23 PM (13 years ago)
I haven't done this step yet with a push enabled app, but I would guess that you need to do everything again for an apple production profile, as it is separate from the dev profile.
 
aquila198
buzztouch Evangelist
Profile
Posts: 473
Reg: Jul 22, 2011
location unknow...
10,330
like
05/31/12 12:33 PM (13 years ago)
Do you have an app that is live using Parse? Were you able to skip this step and make it work?
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
05/31/12 01:01 PM (13 years ago)
I have a few live apps from the days before I discovered Parse and Buzztouch, and with those I have a dev profile for testing on devices and a separate release profile for Apple submissions. They have a * wildcard in them so I only need two for all of those apps. I understand you cannot use wildcards in a profile if enabling push though, although I could be wrong. Right now I have a couple of buzztouch apps with Parse push enabled in development. I am hoping to release them soon and I'm expecting to have to configure a release profile for each these. But I also expect I can re-use my dev profiles for other developments if I give them the same app id.
 
aquila198
buzztouch Evangelist
Profile
Posts: 473
Reg: Jul 22, 2011
location unknow...
10,330
like
05/31/12 01:29 PM (13 years ago)
Thanks for the insight Alan- the certifications certainly throw me for a loop. Good reminder on re-using the dev certification. I just wish it was a bit more clear on the process. It seems that any previsionIng profile would all be replaced by a distribution profile before it goes live.
 
aquila198
buzztouch Evangelist
Profile
Posts: 473
Reg: Jul 22, 2011
location unknow...
10,330
like
05/31/12 05:23 PM (13 years ago)
Do you have an app that is live using Parse? Were you able to skip this step and make it work?
 
Jake Chasan
Veteran developer
Profile
Posts: 1685
Reg: May 13, 2011
location unknow...
29,650
like
08/21/12 12:05 PM (13 years ago)
Does anyone have a sample app that is using parse? If so, is it possible for me to get the source code? (BT2.0). Thanks, Jake
 

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.