【问题标题】:UILocalNotification Special Characters Alert BodyUILocalNotification 特殊字符警报正文
【发布时间】:2012-06-20 18:18:26
【问题描述】:

在 iOS 5.1.1 上生成 UILocalNotification 时,我无法在 alertBody 中显示特殊字符,例如“%”。 Apple 的文档特别指出 '%' char 的字符串格式化程序是 '%%'。

以下是相关代码:

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:20.0];

localNotification.alertBody = [NSString stringWithFormat:@"Test %%"];
NSLog(@"Local notification's alert body is %@",localNotification.alertBody);
localNotification.alertAction = @"View";

localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

如果我尝试绝对指定 alertBody,也会发生同样的事情: localNotification.alertBody = @"测试%";

我尝试了相同的代码来生成一个完美运行的 UIAlertView。这是 iOS 错误吗?

【问题讨论】:

    标签: ios ios5 uilocalnotification ios4


    【解决方案1】:

    我找到了一个涉及使用的部分解决方案

    localNotification.alertBody = @"%%%%"; 
    

    生成一个 '%' 字符。我猜这是iOS中的双重处理错误。

    【讨论】:

      【解决方案2】:

      我知道它说格式化程序是 %% 但通常在字符串中您使用反斜杠 \ 作为转义。因此,请尝试:“Test \%”。

      【讨论】:

      • localNotification.alertBody = @"Test \%";行为与上面完全相同:(“测试”部分已打印,但缺少“%”字符。
      • 它出现了“如果我尝试绝对指定 alertBody 会发生同样的事情:localNotification.alertBody = @"Test %";"在您的帖子中,退格决定擅离职守,我认为您写的内容是正确的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多