我有Json
Array
推送Notification
到达此类,
{
"alert" : "You got your emails.",
"badge" : 9
}
我想立即在iphone的通知栏中显示这个数组ipad
答案 0 :(得分:1)
在AppDelegate
文件中。
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *msg = [[userInfo objectForKey:@"aps"]objectForKey:@"alert"];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"MyTitle" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
这将在您的有效负载中显示您的消息。提供您的申请的时间是background
或foreground
,NOT terminated
。
答案 1 :(得分:0)
使用下面的库在导航栏中显示通知
应用内通知视图,模仿状态栏上方显示的iOS 6通知视图。
功能强>
类似于iOS 6通知的动画和布局
提供两个UILabel和一个UIImageView
简单API
将多个通知排入队列并使用默认值进行显示 持续时间为2秒。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
}
#pragma mark Notification tokan
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
deviceTokenForPushNotification = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
deviceTokenForPushNotification = [deviceTokenForPushNotification stringByReplacingOccurrencesOfString:@" " withString:@""];
NSUserDefaults *objUserDefalut = [NSUserDefaults standardUserDefaults];
[objUserDefalut setValue:deviceTokenForPushNotification forKey:@"DeviceToken"];
[objUserDefalut synchronize];
NSLog(@"My token is: %@", deviceToken);
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSUserDefaults *objUserDefalut = [NSUserDefaults standardUserDefaults];
[objUserDefalut setValue:@"" forKey:@"DeviceToken"];
[objUserDefalut synchronize];
}