是否可以自定义iPhone的本地通知显示?

时间:2013-06-07 03:50:41

标签: ios uilocalnotification

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

- (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++;

}

2 个答案:

答案 0 :(得分:2)

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

我认为文本As happy as a clam at high water," is a very common.....的部分就足够了。如果用户想要查看全文,允许用户打开应用并在那里显示

答案 1 :(得分:0)

applicationDidReceiveLocalNotification 中,添加 UIAlertView ,并将全文显示为提醒。