Ios 在iphone上创建本地通知
我正在尝试创建一个本地通知按钮,如“是否确实要删除是或否?我将如何执行此操作”基于您尝试完成的内容,我认为您不想使用UILocalNotification,看起来您想要的是Ios 在iphone上创建本地通知,ios,uilocalnotification,Ios,Uilocalnotification,我正在尝试创建一个本地通知按钮,如“是否确实要删除是或否?我将如何执行此操作”基于您尝试完成的内容,我认为您不想使用UILocalNotification,看起来您想要的是 希望对您有所帮助基于您正在努力实现的目标,我认为您不想使用UILocalNotification,看起来您想要的是 希望这对你有所帮助你可以像奥斯卡·戈麦斯说的那样,使用UIAlertView 要向按钮添加操作,请首先执行UIAlertViewDelegate并使用以下方法 - (void)alertView:(UIAler
希望对您有所帮助基于您正在努力实现的目标,我认为您不想使用UILocalNotification,看起来您想要的是
希望这对你有所帮助你可以像奥斯卡·戈麦斯说的那样,使用
UIAlertView
要向按钮添加操作,请首先执行UIAlertViewDelegate
并使用以下方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
您可以检查按钮索引
并执行相应的操作(按钮索引为0
“是”,1表示按钮“否”)。您可以使用
UIAlertView
来完成您想要做的事情,就像奥斯卡·戈麦斯所说的那样
要向按钮添加操作,请首先执行UIAlertViewDelegate
并使用以下方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
您可以检查按钮索引
并执行相应的操作(按钮索引为0
“是”,1表示按钮“否”)。试试这个:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Are you sure you want to delete?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Yes", @"No", nil];
alert.tag=1;
[alert show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag==1)
{
if(buttonIndex==0)
{
//Do when click "Yes" button
}
else if(buttonIndex==1)
{
//Do when click "No" button
}
}
}
也许它会对你有所帮助。试试这个:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Are you sure you want to delete?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Yes", @"No", nil];
alert.tag=1;
[alert show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag==1)
{
if(buttonIndex==0)
{
//Do when click "Yes" button
}
else if(buttonIndex==1)
{
//Do when click "No" button
}
}
}
可能会对您有所帮助。AppDelegate文件中的此代码块:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
// Override point for customization after application launch.
return YES;
}
// This code block is invoked when application is in foreground (active-mode)
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
**UIAlertView *notificationAlert = [[UIAlertView alloc] initWithTitle:@“Alert” message:@“Are you sure you want to delete?” delegate:self cancelButtonTitle:nil otherButtonTitles:@“Yes”,@“No”, nil];
notificationAlert.tag = 101;
[notificationAlert show];**
// NSLog(@"didReceiveLocalNotification");
}
**- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag==1) {
if(buttonIndex==0)
{
//Do when click "Yes" button
}
else if(buttonIndex==1)
{
//Do when click "No" button
}
}
}**
此代码块位于任何ViewController的.m文件中:
-(IBAction)startLocalNotification { // Bind this method to UIButton action
NSLog(@"startLocalNotification");
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7];
notification.alertBody = @"This is local notification!";
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 10;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
当按下绑定“startLocalNotification”的按钮时,上述代码在7秒的时间间隔后显示AlertView。
如果应用程序位于后台,则它会将BadgeNumber显示为10,并带有默认通知声音。AppDelegate文件中的此代码块:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
// Override point for customization after application launch.
return YES;
}
// This code block is invoked when application is in foreground (active-mode)
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
**UIAlertView *notificationAlert = [[UIAlertView alloc] initWithTitle:@“Alert” message:@“Are you sure you want to delete?” delegate:self cancelButtonTitle:nil otherButtonTitles:@“Yes”,@“No”, nil];
notificationAlert.tag = 101;
[notificationAlert show];**
// NSLog(@"didReceiveLocalNotification");
}
**- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag==1) {
if(buttonIndex==0)
{
//Do when click "Yes" button
}
else if(buttonIndex==1)
{
//Do when click "No" button
}
}
}**
此代码块位于任何ViewController的.m文件中:
-(IBAction)startLocalNotification { // Bind this method to UIButton action
NSLog(@"startLocalNotification");
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7];
notification.alertBody = @"This is local notification!";
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 10;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
当按下绑定“startLocalNotification”的按钮时,上述代码在7秒的时间间隔后显示AlertView。
如果应用程序位于后台,则它会将BadgeNumber显示为10,并带有默认通知声音。谢谢,这正是我想要的。然后我将如何向按钮添加操作?@matthewmoss设置UIAlertViewDelegate谢谢,这正是我想要的。然后我将如何向按钮添加操作?@matthewmoss设置UIAlertViewDelegate