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 !!!
Related
I've been doing a program which takes care of posting a picture or words (or both) to both facebook and twitter. But I want to do them both at the same time, so I wrote my code like this:
//POST TO FACEBOOK
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
slcvc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[slcvc addImage:bim];
[slcvc setInitialText:tf.text];
[self presentViewController:slcvc animated:YES completion:NULL];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook - not logged in!" message:#"You need to login (or sign up) to successfully post..." delegate:nil cancelButtonTitle:#"Too bad!" otherButtonTitles:nil];
[alert show];
}
//POST TO TWITTER
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
slcvc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slcvc addImage:bim];
[slcvc setInitialText:tf.text];
[self presentViewController:slcvc animated:YES completion:NULL];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Twitter - not logged in!" message:#"You need to login (or sign up) to successfully post..." delegate:nil cancelButtonTitle:#"Too bad!" otherButtonTitles:nil];
[alert show];
}
This is all of course, in an IBAction function that is "file owned" already (slcvc is the SLComposeViewController, bim is an UIImage, and tf.text is the text of the UITextfield tf). And I have posted with this code before, only that it worked separately. If I try to use this to post a picture to Facebook and Twitter at the same time, I get this error:
Attempt to present <SLTwitterComposeViewController: 0xf6265e0> on <ViewController: 0x9476960> which is waiting for a delayed presention of <SLFacebookComposeViewController: 0x9432d70> to complete
(I'm still allowed to post to Facebook but not to Twitter)
I'm sure this happens because the SLComposeViewController registers itself as free to operate again once the first posting (the one for Facebook in this case) is done. So is there a way to have the second posting (the one for Twitter) to wait somehow for the user to send the first posting (to Facebook) and then to present the posting for Twitter? Thanks to anyone in advance for any help or suggestions!!
You will need to use the completion handler of the SLComposeViewController. This is called after user is done composing the post or cancelling it:
[slcvc setCompletionHandler:^(SLComposeViewControllerResult result) {
//POST TO TWITTER
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
slcvc2 = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slcvc2 addImage:bim];
[slcvc2 setInitialText:tf.text];
[self presentViewController:slcvc animated:YES completion:NULL];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Twitter - not logged in!" message:#"You need to login (or sign up) to successfully post..." delegate:nil cancelButtonTitle:#"Too bad!" otherButtonTitles:nil];
[alert show];
}
}
Just try following thing.
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentViewController:fbViewController animated:YES completion:nil];
}];
In iOS 6 the presented MFMailComposeViewController will not dismiss if user attempts to send second email...
Everything works perfectly the first go around and email is sent. However, if email option is selected again the MFMailComposeViewController will not dismiss on cancel.
Here is how I implemented it:
- (IBAction)buttonEmailClick:(id)sender {
if (![MFMailComposeViewController canSendMail]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Can't send" message:#"This device is unable to send emails." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
NSDictionary *contactsInfo = [self contactsInfoFromPlistNamed:kConfigPlistName];
[mailComposeViewController setToRecipients:[NSArray arrayWithObject:[contactsInfo objectForKey:#"email"]]];
//[mailComposeViewController setSubject:kEmailDefaultSubject];
//[mailComposeViewController setMessageBody:text isHTML:NO];
[self presentModalViewController:mailComposeViewController animated:YES];
}
and then this:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
UIAlertView *alert = nil;
if (result == MFMailComposeResultSent) {
alert = [[UIAlertView alloc] initWithTitle:#"Sent" message:#"Your email was sent." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
}
else if (result == MFMailComposeResultFailed) {
alert = [[UIAlertView alloc] initWithTitle:#"Failed" message:#"An error occured and your email was not sent." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
}
[alert show];
[self dismissModalViewControllerAnimated:YES];
}
It works fine in iOS 5 but not in iOS 6. I have tried replacing with non deprecated methods for iOS 6, but it doesn't work.
Have you tried creating a fresh MFMailComposeViewController each time they go to send an email? I'm not sure if you should be reusing it.
You can try this:
MFMailComposeViewController * composer = [[MFMailComposeViewController alloc] init];
composer.delegate = self;
-(void)mailComposeController:didFinishWithResult:error: should be called if you assign that class to the delegate
I get this error when I want to alert user if there is no internet connection
Please help me, Here is my code:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
__block UIAlertView *alert = nil;
//---------- Check Connection -------
// allocate a reachability object
Reachability* reach = [Reachability reachabilityWithHostname:#"www.google.com"];
// set the blocks
reach.unreachableBlock = ^(Reachability*reach) // not connected
{
//NSLog(#"UNREACHABLE!");
alert =
[[UIAlertView alloc]
initWithTitle: #"No Network Connection!"
message:#"Sorry, we can't currently connect you to the app. Please check your internet connection."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
//[alert release];
};
reach.reachableBlock = ^(Reachability*reach)
{
//NSLog(#"REACHABLE!");
};
// start the notifier which will cause the reachability object to retain itself!
[reach startNotifier];
}
The error is "wait_fences: failed to receive reply: 10004003"
Any Suggestions?
I got similar issue before. Because I was trying to display the alertview in a block.
I added the folowing line to my block instead of [alert show]; and everything worked fine.
[alertview performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:false];
Try to update your UI from Main Thread only, else it'll cause issues or show unpredictable results.
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];
}
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.