0

I'm building a small, simple application for iPhone (I'm not that experienced). All it has to do is display a link to a website on it (yes really, thats it). But i need a local notification to fire every week at the same time to alert the user to click the link in the app. Now because I'm not very experienced, i don't really know where to start. I have googled around and found how to repeat a local notification: http://xebee.xebia.in/2011/04/13/local-notifications-in-iphone/. But i dont even know where to put this code?? Do i create a view based application, if so what method do I put the above code in. If someone could give me an outline of what I could do or even just give me some things to google (keywords etc) and I can go off and read up on it. This app is being built out of necessity, not so much my own learning, so I just need to get it done! Any pointers appreciated!

4

2 回答 2

2

使用它来安排通知:

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

    //setting the fire dat of the local notification. Put the date you want the notification to be sent
    localNotification.fireDate = [[[NSDate alloc] init] autorelease]; 

    //setting the time zone
    localNotification.timeZone = [NSTimeZone defaultTimeZone];

    //setting the message to display
    localNotification.alertBody = @"Notification Body";

    //default notification sound
    localNotification.soundName = UILocalNotificationDefaultSoundName;


    localNotification.alertAction = @"Action!";

    //Saving regionIndex and searchIndex
    NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:@"value", @"key", nil];
    localNotification.userInfo = userInfo;
    [userInfo release];

    //schedule a notification at its specified time with the help of the app delegate
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];    
    [localNotification release];

然后,每次用户加载应用程序时,您可以使用 scheduleLocalNotifications 检查下周的通知是否已安排好。

    NSArray *notifications = [NSArray arrayWithArray:[[UIApplication sharedApplication] scheduledLocalNotifications]];
    for (UILocalNotification *notification in notifications) {
        NSDictionary *userInfo = notification.userInfo;
        NSdate *date = notification.fireDate;

        // Here is where you can check if the notification was already scheduled    

    }
于 2012-04-28T05:04:44.077 回答
0

一个单一的视图模板可能是最好的开始。本地通知很容易使用,首先要了解它们是如何工作的以及应该如何使用它们。您布置的场景听起来适合本地通知。首先查看Apple 的文档。有很多关于如何做到这一点的例子。

于 2012-04-08T21:12:12.557 回答