Show UIAlertView that is same as UIRemoteNotification when app is running in foreground
Posted
by
Sidwyn Koh
on Stack Overflow
See other posts from Stack Overflow
or by Sidwyn Koh
Published on 2012-10-28T10:44:40Z
Indexed on
2012/10/28
11:00 UTC
Read the original article
Hit count: 355
I understand that we can handle push notifications via the method:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
and we can check if the app was running in the foreground:
if (application.applicationState == UIApplicationStateActive ) { ... }
How do we show the exact same notification with localisation?
NSString *message = [[[userInfo valueForKey:@"aps"] valueForKey:@"alert"] valueForKey:@"loc-key"];
NSString *trueMessage = NSLocalizedString(message, nil);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
message:trueMessage
cancelButtonItem:@"OK"
otherButtonItems:@"Show", nil];
[alertView show];
This shows the raw unlocalized text, e.g. "You have a new alert from %1@ on %2@."
My question is, how can we place the loc-args
inside the UIAlertView as well, when the app is running in the foreground?
© Stack Overflow or respective owner