代码库> 弹出视图> JKNotifier通知栏提示框,仿系统消息推送状态栏提示框
JKNotifier通知栏提示框,仿系统消息推送状态栏提示框
关注
上传者:hldsjk 分类:弹出视图(Popup View)
查看次数:4036 下载次数:689
上传时间:2015-05-25 大小:829 B
JKNotifier
JKNotifier,when a notification pushed and app is UIApplicationStateActive,JKNotifier wiil show in statusbar like background push
JKNotifier,当有消息推送过来并且app为UIApplicationStateActive的时候,JKNotifier将会在状态栏中显示,就如后台推送一样。

Useage
Manual show
- (IBAction)showAutoHiddenTouched:(id)sender {
[JKNotifier showNotifer:@"亲,您收到了一条自动隐藏的消息哦!"];

[JKNotifier handleClickAction:^(NSString *name,NSString *detail, JKNotifier *notifier) {
    [notifier dismiss];
    NSLog(@"AutoHidden JKNotifierBar clicked");
}];
}

UILocalNotification or UIRemoteNotification
- (IBAction)localNotificationTouched:(id)sender {
UILocalNotification *notification=[[UILocalNotification alloc] init];
if (notification!=nil) {
    NSDate *now=[NSDate date];
    notification.fireDate=[now dateByAddingTimeInterval:2];
    notification.timeZone=[NSTimeZone defaultTimeZone];
    notification.alertBody=@"收到定时本地推送通知!(recived a UILocalNotification)";
    notification.soundName = @"default";
    [notification setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
NSLog(@"本地通知2秒后触发");
}

//appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    UIUserNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}else
{
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}
    return YES;
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

if (application.applicationState == UIApplicationStateActive) {
    [JKNotifier showNotifer:notification.alertBody];
    }
}

测试环境:Xcode 6.2,iOS 6.0以上




收藏
我来说两句
发表评论
您还没有登录!请登录注册
所有评论(0


综合评论
提示
sina weixin mail 回到顶部