App with playerduel functionality doesn't get push notification - iphone

I am developing application which support playerduel framework. In which two players can play with each other. Person can send challenge to another one.
i follow the documentation following. https://docs.urbanairship.com/display/DOCS/Getting+Started%3A+iOS%3A+Push
I can get notification when i send it from command line (for testing) as describe in above documentation. But when i play game. Playerdual can't send notification when some one send challenge to another.
appdelegate code :-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Init Airship launch options
NSMutableDictionary *takeOffOptions = [[[NSMutableDictionary alloc] init] autorelease];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
// Create Airship singleton that's used to talk to Urban Airship servers.
// Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
[UAirship takeOff:takeOffOptions];
// Register for notifications
[[UAPush shared]registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
// Override point for customization after application launch.
self.appStarted = YES;
UIImage *bgImage= [UIImage imageNamed:#"default.png"];
[PlayerDuel initializeWithGameKey:#"gamekey" andBackground:bgImage
andDelegate:[navigationController.viewControllers objectAtIndex:0] andOrientation:UIInterfaceOrientationPortrait];
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(#"deviceToken:- %#",deviceToken);
// Updates the device token and registers the token with UA
[[UAPush shared] registerDeviceToken:deviceToken];
[PlayerDuel registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
for (id key in userInfo) {
NSLog(#"key: %#, value: %#", key, [userInfo objectForKey:key]);
}
NSLog(#"remote notification: %#",[userInfo description]);
NSDictionary *apsInfo = [userInfo objectForKey:#"aps"];
NSString *alert = [apsInfo objectForKey:#"alert"];
NSLog(#"Received Push Alert: %#", alert);
NSString *sound = [apsInfo objectForKey:#"sound"];
NSLog(#"Received Push Sound: %#", sound);
NSString *itemName = #"my app";
NSString *messageTitle = [apsInfo objectForKey:#"alert"];
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive){
AudioServicesPlaySystemSound(1007);
[self _showAlert:messageTitle withTitle:itemName];
}
else{
UIViewController *viewController = navigationController.visibleViewController;
// NSLog(#"Controller Name:- %#",viewController);
[viewController.view reloadInputViews];
[viewController playerDuelStartGame:nil];
}
NSString *badge = [apsInfo objectForKey:#"badge"];
NSLog(#"Received Push Badge: %#", badge);
}

If the push notifications work directly through Urban Airship and not through PlayerDuel, You probably didn't specify the right urban airship details in PlayerDuel's developers website. Make sure you put Urban Airship's Master Secret and not the App Secret in PlayerDuel's website.

I have used App Secrete as Urban Airship Key: . This is wrong. When i change it value as App Key . It works fine.

Related

AppleWatch : On button tap from the the AppleWach Open URL on iPhone device

I want to open url from the AppleWatch app button tap to the mobile application.
Please any one have any idea regarding to these?
Added this in your AppDelegate.m
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
This is what you have to apply on button tap in Watch App
NSURL *url = // your URL
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:url, #"URLKey", nil];
[WKInterfaceController openParentApplication:dic reply:^(NSDictionary *replyInfo, NSError *error)
{
NSLog(#"%# %#",replyInfo, error);
}];
And you can receive this request in iPhone in AppDelegate.m
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
{
//receive userinfo dictionary here to perform specific request from watch
NSString *url = [userInfo objectForKey:#"URLKey"];
// perform operation on url
reply(#{#"Notification Alert":[NSString stringWithFormat:#"%f",dist]});
}

how to handle push payload when the app closed?

i am sending push payload to my users with the follow content :
{"aps": {"alert": "Go To Google", "sound": "Default","url":"http://www.google.com"}}
everything goes well when the pp is running but in the background.
if i am receiving the push and the app is closed i am open it and nothing happen.
i am trying to redirect to this url in the payload.
again when the app is running from the background it goes well.
this is the implementation so far AppDelegate.m:
-(void)Redirect:(NSString*)url{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
NSLog(#"%#",url);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
RedirectedUri = [[userInfo objectForKey:#"aps"] objectForKey:#"url"];
NSLog(#"%#",RedirectedUri);
[self Redirect:RedirectedUri];
}
need some help please.
Additionally, add the following to your code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self applicationDidFinishLaunching:application];
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
RedirectedUri = [[dictionary objectForKey:#"aps"] objectForKey:#"url"];
[self Redirect:RedirectedUri];
}
}
return YES;
}

Get device token to push notify the second time on iPhone

I need to obtain the device token on my iPhone to test the push notify.
On my iPhone I had already agreed to notify push permissions. I try to remove and reinstall the app but nothing. I try to put a breackpoint in the didRegisterForRemoteNotificationsWithDeviceToken method but nothing.
Any suggestion?
This is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/**** PUSH NOTIFY ****/
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSMutableString *str = [[NSMutableString alloc] initWithFormat:#"http://www.mysite.com/storeToken.php?task=register&token=%#", [self stringWithDeviceToken:deviceToken]];
//NSLog(#"%#",str);
NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];
[pref setObject:[self stringWithDeviceToken:deviceToken] forKey:#"token"];
[pref synchronize];
NSURL *url = [NSURL URLWithString:str];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
[str release];
}
- (NSString*)stringWithDeviceToken:(NSData*)deviceToken {
const char* data = [deviceToken bytes];
NSMutableString* token = [NSMutableString string];
for (int i = 0; i < [deviceToken length]; i++) {
[token appendFormat:#"%02.2hhX", data[i]];
}
return [[token copy] autorelease];
}
This is the error that it print:
Error: Error Domain=NSCocoaErrorDomain Code=3000 "nessuna stringa di autorizzazione 'aps-environment' valida trovata per l'applicazione" UserInfo=0x296e80 {NSLocalizedDescription=nessuna stringa di autorizzazione 'aps-environment' valida trovata per l'applicazione}
It is good to have another delegate method for error handling:
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(#"Fail to register for remote notifications: %#", [error localizedDescription]);
}
After question update it's more clear that problem is in wrong provisioning profile (generic or without 'aps-evironment'). So:
Remove all expired profiles and all profiles for that app from both XCode and device
Check push notifications are enabled for your app (in provisioning portal)
Download provisioning profile from portal, install it to XCode
Check that selected profile (in build settings / codesigning identity) matches the app, and is not the generic/wildcard one (sometimes autoselection goes wrong)
As usual (XCode caching "magic"), it's better to restart XCode and remove the application from device before build
Build & Pray

How to manage notification when users click on badge

I have a question to ask about notifications. After some hours to learn how to implement push notifications on iPhone, it now arrives!
How do I manage users that click on badge or click view on alert? What happen when users click there?
I tried to send me some notification and the number on the icon of application in springboard increments. In which way clicking there it's possible to show a uiview to manage the notification arrived and show the message read and unread?
Is there a tutorial for it? I want to save all the messages inside a uitableview.
You want to read Handling Local and Remote Notifications
Basically in your application delegate, you want to implement:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
and
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
And process the launchOptions / userInfo for the notification data.
How I normally process the data is:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary* userInfo =
[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo) {
[self processRemoteNotification:userInfo];
}
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[self processRemoteNotification:userInfo];
}
The format for userInfo is documented the The Notification Payload section.
e.g. the "aps" key will give you another NSDictionary, then looking up the "alert" key will give you the alert message that was displayed. Also, any custom data you send in the JSON payload will be in there as well.
NSDictionary *apsInfo = [userInfo objectForKey:#"aps"];
NSString *alertMsg = #"";
NSString *badge = #"";
NSString *sound = #"";
NSString *custom = #"";
if( [apsInfo objectForKey:#"alert"] != NULL)
{
alertMsg = [apsInfo objectForKey:#"alert"];
}
if( [apsInfo objectForKey:#"badge"] != NULL)
{
badge = [apsInfo objectForKey:#"badge"];
}
if( [apsInfo objectForKey:#"sound"] != NULL)
{
sound = [apsInfo objectForKey:#"sound"];
}
if( [userInfo objectForKey:#"Custom"] != NULL)
{
custom = [userInfo objectForKey:#"Custom"];
}

iPhone client not registering for push?

I "think" my app is not registering for push notifications.
It should be as simple as adding the code to didFinishLaunchingWithOptions and then the when tested the app alert for push notifications should (but does not in my case) pop up.
my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];
return YES;
}
This is an iPad app. It is running without push on my real device so I assume the provisioning is correct.
Any ideas? I do not get the push Don't allow/ok pop up.
Do u have this code in your delegate?
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString
stringWithFormat:#"Device Token=%#",deviceToken];
NSLog(str);
}
You should get the device token generated and put it in your server where you want to push your notification..
If let say you have everything right on the iphone part, the problem may lies on your server code where you push your notification..
Take a look at this tutorial about push notification :
http://mobiforge.com/developing/story/programming-apple-push-notification-services
You need to implement the delegate methods and set up the certificates on your server. Here is some code for the objc side:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
NSString *token = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
[[NSUserDefaults standardUserDefaults] setObject:token forKey:#"token"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithString:#""] forKey:#"token"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleDisplayName"]
message:[[userInfo objectForKey:#"aps"] objectForKey:#"alert"]
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil] autorelease];
[alert show];
}
A good tutorial about setting up the server and Dev Center certs - How to renew your Apple Push Notification Push SSL Certificate
How to build an Apple Push Notification provider server (tutorial)
Yes I have the other part of the code also. I was under the impression that the pop up would happen weather the server stuff was done yet or not?
I got it working. I had to get a new provisioning file. Delete the old one. The go into the app folder. View contents of the project file. Open with text editor the file with the provisioning key in it and swap the key (two spots) out with the new key code.
Now it works. Thanks for the help.