Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
我想使用objective c为ios应用程序中的本地通知设置不同的警报正文_Ios_Objective C_Uilocalnotification - Fatal编程技术网

我想使用objective c为ios应用程序中的本地通知设置不同的警报正文

我想使用objective c为ios应用程序中的本地通知设置不同的警报正文,ios,objective-c,uilocalnotification,Ios,Objective C,Uilocalnotification,我正在从地址簿中提取联系人&通过为每个通知提取不同的联系人姓名来显示警报正文,但它不起作用 这是我警觉的身体:--(@“问%@你好,最近怎么样?”,姓名) 这是我的密码 -(void)setNotificationlocal{ //get random contacts from adress book NSUInteger randomIndex = arc4random() % [self.localContactArray count]; NSLog(@"rando

我正在从地址簿中提取联系人&通过为每个通知提取不同的联系人姓名来显示警报正文,但它不起作用

这是我警觉的身体:--(@“问%@你好,最近怎么样?”,姓名)

这是我的密码

-(void)setNotificationlocal{

    //get random contacts from adress book
   NSUInteger randomIndex = arc4random() % [self.localContactArray count];
    NSLog(@"random index---%lu",(unsigned long)randomIndex);
    NSString *name;
    NSString *mobNumber;
    if ([[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"lName"] isEqualToString:@"<null>"] || [[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"lName"] isEqualToString:@""] || [[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"lName"]isEqualToString:@"(null)"]||[[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"lName"]  isKindOfClass:[NSNull class]]  || [[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"lName"] == nil){

        name=[[NSString alloc]initWithFormat:@"%@",[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"fName"]];
        mobNumber=nil;
        mobNumber=[[NSString alloc]initWithString:[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"num"]];
    }else{

        name=[[NSString alloc]initWithFormat:@"%@ %@",[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"fName"],[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"lName"]];
        mobNumber=nil;
        mobNumber=[[NSString alloc]initWithString:[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"num"]];
    }


    // New for iOS 8 - Register the notifications

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    if (notification)
    {
            notification.timeZone = [NSTimeZone defaultTimeZone];
            if ( [statusString isEqualToString:@"daily"]) {

                notification.fireDate =[NSDate dateWithTimeIntervalSinceNow:86400];
               // notification.repeatInterval = NSCalendarUnitDay;
               NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
                [defaults setObject:@"daily" forKey:@"KEY_NAME"];
                [defaults synchronize];

            }else if ( [statusString isEqualToString:@"weekly"]) {

                notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:604800];
               // notification.repeatInterval = NSCalendarUnitWeekOfYear;
               NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
                [defaults setObject:@"weekly" forKey:@"KEY_NAME"];
                [defaults synchronize];

            }else if ( [statusString isEqualToString:@"fortnightly"]) {
                notification.fireDate =  [NSDate dateWithTimeIntervalSinceNow:1209600];

//                notification.userInfo = @{@"notification_identifier":@"After14Days"};
//                notification.fireDate = [[NSDate date] dateByAddingTimeInterval:(60*60*24*14)];
//                notification.repeatInterval = NSCalendarUnitDay;
               NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
                [defaults setObject:@"fortnightly" forKey:@"KEY_NAME"];
                [defaults synchronize];

            }else{
                notification.repeatInterval = 0;
            }

            notification.alertBody = [NSString stringWithFormat:@"Ask %@ How you doin, How you been?",name];
            notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
            notification.soundName = UILocalNotificationDefaultSoundName;

        notification.alertAction = @"say yes";
        notification.timeZone = [NSTimeZone defaultTimeZone];
        notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
       // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showSMS) name:@"showSMS" object:nil];

        // this will schedule the notification to fire at the fire date
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    }
}
-(void)setNotificationlocal{
//从地址簿中随机获取联系人
NSInteger randomIndex=arc4random()%[self.localContactArray count];
NSLog(@“随机索引---%lu”,(无符号长)随机索引);
NSString*名称;
NSString*mobNumber;
if([[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”]IseQualtString:@”“][[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”]IseQualtString:@”“][[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”]IseQualtString:@”(null)]||[[[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”]isKindOfClass:[NSNull class]]| |[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”]==nil){
name=[[NSString alloc]initWithFormat:@“%@”,[[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“fName”];
mobNumber=零;
mobNumber=[[NSString alloc]initWithString:[[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“num”];
}否则{
名称=[[NSString alloc]initWithFormat:@“%@%@”,[[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“fName”],[[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”];
mobNumber=零;
mobNumber=[[NSString alloc]initWithString:[[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“num”];
}
//iOS 8新增功能-注册通知
UILocalNotification*通知=[[UILocalNotification alloc]init];
如果(通知)
{
notification.timeZone=[NSTimeZone defaultTimeZone];
如果([statusString IsequalString:@“daily”]){
notification.fireDate=[NSDate datewithtimeintervalsince:86400];
//notification.repeatInterval=NSCalendarUnitDay;
NSUserDefaults*默认值=[NSUserDefaults standardUserDefaults];
[默认设置setObject:@“daily”forKey:@“KEY_NAME”];
[默认同步];
}else if([statusString IsequalString:@“weekly”]){
notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:604800];
//notification.repeatInterval=NSCalendarUnitWeekOfYear;
NSUserDefaults*默认值=[NSUserDefaults standardUserDefaults];
[默认设置setObject:@“weekly”forKey:@“KEY_NAME”];
[默认同步];
}else if([statusString IsequalString:@“每两周”]){
notification.fireDate=[NSDate datewithtimeintervalsince:1209600];
//notification.userInfo=@{@“通知标识符”:@“14天后”};
//notification.fireDate=[[NSDate date]dateByAddingTimeInterval:(60*60*24*14)];
//notification.repeatInterval=NSCalendarUnitDay;
NSUserDefaults*默认值=[NSUserDefaults standardUserDefaults];
[默认设置setObject:@“每两周一次”forKey:@“KEY_NAME”];
[默认同步];
}否则{
notification.repeatInterval=0;
}
notification.alertBody=[NSString stringWithFormat:@“Ask%@你好,最近怎么样?”,name];
notification.applicationBadgeNumber=[[UIApplication sharedApplication]applicationBadgeNumber]+1;
notification.soundName=UILocalNotificationDefaultSoundName;
notification.alertAction=@“说是”;
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.applicationBadgeNumber=[[UIApplication sharedApplication]applicationBadgeNumber]+1;
//[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(showSMS)name:@“showSMS”对象:nil];
//这将安排在火灾日期发出火灾通知
[[UIApplication sharedApplication]scheduleLocalNotification:notification];
}
}
,您只需检查

if ([[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"lName"] == nil)
{
    name=[[NSString alloc]initWithFormat:@"%@",[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"fName"]];
}
else
{
    name=[[NSString alloc]initWithFormat:@"%@ %@",[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"fName"],[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"lName"]];
}
    mobNumber=[[NSString alloc]initWithString:[[self.localContactArray objectAtIndex:randomIndex] objectForKey:@"num"]];

现在发生了什么?作为旁白,下面这一行是一个令人憎恶的:
如果([[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”]IsequalString:@”“][[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”]IsequalString:@][[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”]isEqualToString:@“(null)”]| |[[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”]isKindOfClass:[NSNull类]]|[[self.localContactArray objectAtIndex:randomIndex]objectForKey:@“lName”==nil){
但请帮助某些人在本地通知中显示不同的警报正文。您何时调用setNotificationlocal方法?根据您的代码,我认为每次调用警报正文时,警报正文都是不同的,因为名称来自随机人。当我当时选择通知时间时,使用此方法时,我如何为您选择不同的联系人姓名每份通知