1

我正在为我的 iphone“谚语”应用程序使用本地通知。每天(上午 11 点 53 分)应该将我的应用程序中的一句话通知给用户。我的问题是,我没有得到任何适当的参考来使用 userinfo 属性,所以我试图以另一种方式做到这一点。我使用了一个整数变量,每次都会增加,当应用程序收到通知时,但这也不能正常工作,本地通知每天都显示相同的说法..请帮我解决这个问题.. . 这是我的代码.....

- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ;

NSDateComponents *componentsForReferenceDate =

[calendar components:(NSDayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit )        fromDate:[NSDate date]];

[componentsForReferenceDate setDay:11] ;
[componentsForReferenceDate setMonth:6] ;
[componentsForReferenceDate setYear:2013] ;

NSDate *referenceDate = [calendar dateFromComponents:componentsForReferenceDate] ;

// set components for time 7:00 a.m.

NSDateComponents *componentsForFireDate =

[calendar components:(NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit|   NSSecondCalendarUnit ) fromDate: referenceDate];

[componentsForFireDate setHour:11] ;
[componentsForFireDate setMinute:53] ;
[componentsForFireDate setSecond:0] ;

NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];

// Create the notification

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

notification.fireDate =  [NSDate dateWithTimeIntervalSinceNow:1];//fireDateOfNotification    ;
notification.timeZone = [NSTimeZone localTimeZone] ;
notification.alertBody = [obj.proverb objectAtIndex:sectionindex];//[objz[NSString   stringWithFormat: @"അകലത്തെ ബന്ധുവിനേക്കാൾ അരികത്തെ ശത്രു നല്ലത് ."] ;
notification.alertAction = @"go back";
notification.userInfo= [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Some information"] forKey:@"information"];
notification.repeatInterval= NSDayCalendarUnit ;
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notification] ;


}

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
DataHandler *obj=[[DataHandler alloc] init];
static int i=0;
NSLog(@"hai");
UILabel *label=[UILabel alloc];
UILabel *label1=[UILabel alloc];


label.text=[obj.explanation objectAtIndex:i];
label1.text=[obj.proverb objectAtIndex:i];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:label1.text
                                                  message:label.text
                                                 delegate:nil
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];
[message show];
i++;
sectionindex++;

}

4

2 回答 2

2

您只能自定义操作按钮(hasAction = NO)。您不能对显示的文本做任何事情。如果文本长度更长,它将仅显示文本的一部分。

我觉得正文As happy as a clam at high water," is a very common.....部分就够了。如果用户想查看全文,允许用户打开应用程序并在那里显示

于 2013-06-07T04:05:23.200 回答
0

在您的applicationDidReceiveLocalNotification中,包含一个UIAlertView和全文显示作为警报。

于 2013-06-07T04:23:45.300 回答