How to receive Push notification message in iphone app? - objective-c

I created .pem file following steps
Log-in to the iPhone Developer Program Portal.
Choose App IDs from the menu on the right.
Create an App ID without a wildcard.
Click the Configure link next to this App ID and then click on the button to start the wizard to generate a new Development Push SSL Certificate.
Download this certificate and double click on aps_developer_identity.cer to import it into your Keychain
Launch Keychain Assistant and click on My Certificates on the left
Expand Apple IOS Development Push Services and select Apple IOS Development Push Services AND my private key
Right-click and choose "Export 2 elements..." and save as cert.p12.
Open Terminal and change directory to location used to save cert.p12 and convert the PKCS12 certificate bundle into PEM format using this command
openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts
10.Now i use this PEM file as my certificate in ApnsPHP!
while i use the url in the browser it display; {"aps":{"alert":"hi","badge":1,"sound":"beep.wav"}}
I am using this code to receive notification in iphone app
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
NSLog(#"\n\n\n\nRegistering for push notifications...\n\n\n\n");
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
NSString *token = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
token = [token stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"\n\n\n\n\n device token===%#\n\n\n\n",token);
//DeviceRegisterer *registrar = [[DeviceRegisterer alloc] init];
//[registrar registerDeviceWithToken:token];
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(#"failed to regiser %#", err);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(#"notification options %#", userInfo);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Super" message:#"welcome" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
for (id key in userInfo) {
NSLog(#"key: %#, value: %#", key, [userInfo objectForKey:key]);
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Your title here!" message:#"this gets covered" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
myTextField.text = [userInfo objectForKey:key];
[myAlertView addSubview:myTextField];
[myAlertView show];
[myAlertView release];
}
}
But am not able to receive the notification message.
Please help to resolve this problem.
Thanks in advance,
Senthilkumar

You are not using a server to send the message. The pem key is meant to be used by a server to send the message. I think that you cannot use your iphone app to send directly a push message.
If your server is using php try to find in this site the code to delivery the notifications.
Note: On my server the ApnsPHP code do not work at all, I used a simple php script found in stackOverflow (sorry do not remember the link) to manage it and works.

I solved this problem. Problem in the php .pem file attactment . thanks for gave idea.

Related

iOS: How to hook into MPMoviePlayerController?

Okay so i am wanting to create a tweak that hooks into the MPMovieController.h file and changes the scaling button to another button. So firstly i checked i can hook into that class just for testing reason, so i hooked into the play function to see if when a video had began playing if i could show a UIAlertView. However I was unable to do so. Even though everything compiled fine and the DEB file was built successfully I still can not get this message to appear when the movie player is playing.
This is my Code:
Tweak.xm:
#import <UIKit/UIKit.h>
#interface MPMoviePlayerController
-(void)play;
#end
%hook MPMoviePlayerController
-(void)play
{
NSString *Title = [NSString stringWithFormat:#"Title", nil];
NSString *message = [NSString stringWithFormat:#"Message", nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:Title message:message delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
%orig;
}
%end
Thanks. P.S. After Installing I have reset and re-sprung my iphone.

UIAlertView for user to download another app

I downloaded an app from app store and noticed that once I installed and opened the app, I got a UIAlertView suggesting that I download another app..
How can I achieve this? Are there any existing code that I can be directed towards?
Seems like a simple feature but I'd like to integrate it. Please see attachment
Here is my edited code, but the 'Hello' button won't link anywhere.. What am I doing wrong?
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Hello World!"
message:#"This is your first UIAlertview message."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Hello", nil];
[message show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Hello"])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"https://itunes.apple.com/gb/app/islam/id667021108?mt=8&affId=1930871&ign-mpt=uo%3D4"]];
}
}
first you have to make alertView, if you want to show the alert as first thing but this code inside (ViewDidLoad) method
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"your title"
message:#"your message"
delegate:self
cancelButtonTitle:#"Not now"
otherButtonTitles:#"Download now"
, nil];
[alert show];
after viewDidLoad but this method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"here but your application link"]];
}else{
}
}
//=================================================//
To know what's NSUserDefaults, I suggest to take a look the official doc.
And of course you can use it to fulfill your goal. You use a user default to store information about the current amount of runs in the app.
More or less like:
BOOL NotTheFirstTime = [[NSUserDefaults standardUserDefaults] boolForKey:#"NotTheFirstTime"];
if(!NotTheFirstTime){
// Show the alert view
// Then set the first run flag
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"NotTheFirstTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if that help you please make it the best question.
It is pretty simple:
1) Set up an UIAlertView as usual with the text and the button titles you like.
2) Set up the UIAlertView's delegate and use this method to figure out which button was clicked (whether the user does or does not want to go to the App Store):
alertView:clickedButtonAtIndex:
3) If the user wants to go to the App Store, open up an App Store link:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"<#This is your App Store Link#>"]];

QucikBlox: Push Notification not working properly

I am trying to send push notification from Admin panel. It shows message sent successfully but I am NOT getting the message as push notification on device.
Also I am not able to send push notification from application.
Code:
QBMPushMessage *message = [[QBMPushMessage alloc] initWithPayload:payload];
// Send push
[QBMessages TSendPush:message toUsers:[NSString stringWithFormat:#"%d", self.opponent.ID] delegate:self];
in delegate method:
else if([result isKindOfClass:[QBMSendPushTaskResult class]])
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
// Success result
if(result.success)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Message sent successfully" message:nil delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil];
//[alert show];
[alert release];
// Errors
}
}
Please see below images :
ok Solved.
I have to create new development certification according to How to create APNS certificates.
Also my previous certificate was Push Notification enabled and working fine with API 1.4. I don't know what was the problem with old certificate !!!

UIAlertView delegate methods don't response on iOS 5.1

I created an instance of UIAlertView with two buttons and in the interface file of my class(.h) I set the delegate too but still cant get any response when clicking the buttons. Here is my code:
//myClass.h
#interface MainMenu : UIViewController<UIAlertViewDelegate>
-(IBAction)secondAct:(id)sender;
And the implementation
-(IBAction)secondAct:(id)sender
alert = [[UIAlertView alloc] initWithTitle:#"Dear User"
message:#"Your Request Will be Sent To Security"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[alert show];
[alert autorelease];
}
and the delegate method:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(#"UIAlertView delegate works");//this line too isnt displayed
NSString *title=[ alertView buttonTitleAtIndex:buttonIndex ];
if ([title isEqualToString:#"OK"]) {
NSLog(#"OK Pressed");
}//i want to create something like this
}
I did all of the code above but still can't take any action. Whichever of the buttons i click, it dissmisses the alert. What is wrong with this code can any one help?
ANSWER
Dear PeterG. commented to change delegete:nil with delegate:self and it works now.
Delegate should probably be set to self. If it generates an error post it here.
Also I do not think you should autorelease the alert ivar. Try to skip that line and see what happens?
Just give the delegate "self".
-(IBAction)secondAct:(id)sender
alert = [[UIAlertView alloc] initWithTitle:#"Dear User"
message:#"Your Request Will be Sent To Security"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[alert show];
}

Trying to Integrate Mail Into my app, getting 2 warnings

I'm trying to integrate sending mail into my app, but I end up with 2 warnings. I am using Obj-C, the Cocos2d Framework. This is my code.
-(void) mailTapped: (id) sender {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:#"", nil]];
[composer setSubject:#"Check Out This Awesome App!"];
[composer setMessageBody:#"I found this great game on the App Store! It's called Mole Attack. It's a side scroller with an epic story. You can check out some screenshots of the gameplay and download it here. Download link - " isHTML:NO]; //Include link and pics
[self presentModalViewController:composer animated:YES]; // <--- warning - GameOver (name of class) may not respond to '-presentModalViewController:animated:'
}
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES]; // <--- warning - GameOver may not respond to '-dismissModalViewControllerAnimated:YES'
if (result == MFMailComposeResultFailed) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failed" message:#"The email was not sent. You must be in wifi or 3G range. Try again later." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Thanks in advance!
Are you sure your GameOver class is inheriting from UIViewController? That's the class that defines the two methods that you're getting warnings about.