在AppDelegate.m,註冊類型的用戶交互的應用程序支持(從iOS的8.0和更高)
UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert);
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
內執行此按鈕抽頭方法:
NSDate * fireDate; // The schedule date time.
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = fireDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = @"alertText";
localNotification.alertAction = @"buttonTitle";
localNotification.soundName = UILocalNotificationDefaultSoundName;
// Schedule it with the app
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
在AppDelegate中.m添加此方法以處理當本地通知到達時(如有必要):
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)localNotification{
// This method gets called when a local notification arrives
}
您是什麼意思由noti fication?推送通知? –
嗯,我認爲我的目的,我只需要一個本地通知。 – DSmith
你是什麼意思本地通知?就像預定時間出現在應用中的popover一樣? –