iOS學習筆記31-本地通知

來源:互聯網
上載者:User

標籤:

建立並調用本地通知的幾個步驟

1,建立本地通知

2,設定處理時間

3,設定通知主體

4,可以設定傳遞的參數userinfo

5,調用通知

 

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

    

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.window.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];

    

    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:23/255.0 green:180/255.0 blue:237/255.0 alpha:1]];

    [[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];

    

    ViewController *viewController = [[ViewController alloc]init];

    self.window.rootViewController = viewController;

    

    [self.window makeKeyAndVisible];

    

    

    

    if ([[UIApplication sharedApplication]currentUserNotificationSettings].types != UIUserNotificationTypeNone) {

        [self addLocalNotification];

    }else{

        [[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound  categories:nil]];

    

    

    

    }

    // Override point for customization after application launch.

    return YES;

}

 

 

 

 

 

 

 

 

 

 

-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings

{

    if (notificationSettings != UIUserNotificationTypeNone) {

        [self addLocalNotification];

    }

 

 

}

 

 

 

 

 

 

-(void)addLocalNotification{

    UILocalNotification *notification = [[UILocalNotification alloc]init];

    

    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:2.0];

    notification.repeatInterval = 2;

    

    notification.alertBody = @"該睡覺了哦!~~";

    notification.applicationIconBadgeNumber = 2;

    notification.alertAction = @"開啟應用";

    

    notification.alertLaunchImage = @"Default";

    notification.soundName = @"msg.caf";

 

    notification.userInfo = @{@"id":@1,@"name":@"dsn"};

    [[UIApplication sharedApplication]scheduleLocalNotification:notification];

 

}

 

 

 

- (void)applicationWillEnterForeground:(UIApplication *)application {

    

    [[UIApplication sharedApplication]setApplicationIconBadgeNumber:0];

    

    

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

 

iOS學習筆記31-本地通知

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.