Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 本地通知问题?_Iphone_Localnotification - Fatal编程技术网

Iphone 本地通知问题?

Iphone 本地通知问题?,iphone,localnotification,Iphone,Localnotification,我是iPhone应用程序开发新手。我正在做报警应用程序。在这个应用程序中,我使用本地通知。我正在“完成”按钮操作中调用通知方法。现在,我单击“完成”按钮意味着通知已正确触发。然后再次点击意味着也被解雇,一次又一次按下意味着工作错误,但我被用来通知火灾日期的时间相同。在此时间内,完成意味着再次用户单击完成按钮意味着再次触发通知 我想在那个特定的时间解雇你。你能帮帮我吗 这里我使用的是这个源代码 -(IBAction)doneButton { [self scheduledNotifica

我是iPhone应用程序开发新手。我正在做报警应用程序。在这个应用程序中,我使用本地通知。我正在“完成”按钮操作中调用通知方法。现在,我单击“完成”按钮意味着通知已正确触发。然后再次点击意味着也被解雇,一次又一次按下意味着工作错误,但我被用来通知火灾日期的时间相同。在此时间内,完成意味着再次用户单击完成按钮意味着再次触发通知

我想在那个特定的时间解雇你。你能帮帮我吗

这里我使用的是这个源代码

-(IBAction)doneButton
{

    [self scheduledNotification];

}

-(void)scheduledNotification
{
    Resource *resourceLoader = [[Resource alloc] init];

     NSDictionary *prefDic = [resourceLoader getPlistDataAsDictionary:@"preference"];

    if ([@"ON" isEqualToString:[prefDic objectForKey:@"alarm"]]) 
    {

        [[UIApplication sharedApplication] cancelAllLocalNotifications];

        Class cls = NSClassFromString(@"UILocalNotification");
        if (cls != nil) 
        {
            NSString *musicName;
            //NSDate *selectedDateTime = [[NSDate alloc]init];

            selectedDateTime = [prefDic objectForKey:@"alarmtime"];
            NSLog(@"saravanan periyasamy %@", selectedDateTime);

            musicName = [NSString stringWithFormat:@"%@%@",[prefDic objectForKey:@"alarmmusic"],@".wav" ];

            NSLog(@"musicname %@", musicName);

            NSLog(@"saravanan periyasamy123 %@", selectedDateTime);
            UILocalNotification *notif = [[cls alloc] init];

            notif.fireDate = selectedDateTime;  /* time for fireDate*/

            NSLog(@"selectedtime %@",selectedDateTime);

            notif.timeZone = [NSTimeZone systemTimeZone];

            notif.alertBody = @"Alarm";
            notif.alertAction = @"Show me";
            notif.repeatInterval = 0;

            notif.soundName = musicName;
            notif.applicationIconBadgeNumber = 1;
            NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"saravanan"
                                                                 forKey:kRemindMeNotificationDataKey];
            notif.userInfo = userDict;
            [[UIApplication sharedApplication] scheduleLocalNotification:notif];
            [notif release];
        }
    }
}


AppDelegate.m



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   Class cls = NSClassFromString(@"UILocalNotification");

    if (cls) {
        UILocalNotification *notification = [launchOptions objectForKey:
                                             UIApplicationLaunchOptionsLocalNotificationKey];

        if (notification) {
            NSString *reminderText = [notification.userInfo 
                                      objectForKey:kRemindMeNotificationDataKey];
            //[self.viewController showReminder:reminderText];
            [self.settingViewController showReminder1:reminderText];
        }
    }
    application.applicationIconBadgeNumber = 0;   
    return YES;    

}

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

    application.applicationIconBadgeNumber = 0;
}

- (void)application:(UIApplication *)application 
didReceiveLocalNotification:(UILocalNotification *)notification {



    application.applicationIconBadgeNumber = 0;
    NSString *reminderText = [notification.userInfo
                              objectForKey:kRemindMeNotificationDataKey];
    //[self.viewController showReminder:reminderText];
    [self.settingViewController showReminder1:reminderText];
}

嗨,我不明白你的问题是什么,但我在这里发布了我的LocalNotification示例代码,只是比较一下,或者使用这个示例

在这里,当用户单击“完成”按钮,然后调用“btnGo_Clicked”方法

做一些改变,你就得到了你的输出

我希望这个答案能帮助你


:)

如果需要多次按下按钮,请删除此行

[[UIApplication sharedApplication] cancelAllLocalNotifications];  

因为它会删除您以前的所有通知。

而且当您的通知弹出窗口时,您的应用程序必须关闭,如果应用程序已打开,则通知不会弹出。。。
[[UIApplication sharedApplication] cancelAllLocalNotifications];