JPE*_*EG_ 17 xcode objective-c ios uilocalnotification
我有一些非常恼人的问题UILocalNotification.
在完成我几乎完成的应用程序时,我注意到无论我尝试了什么,我都无法获得本地通知.
所以我没有浪费时间,而是决定回到基础,看看我是否可以让他们工作.
我创建了一个新的基于XCode视图的应用程序,并替换-viewDidLoad为:
- (void)viewDidLoad
{
UILocalNotification * theNotification = [[UILocalNotification alloc] init];
theNotification.alertBody = @"Alert text";
theNotification.alertAction = @"Ok";
theNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
[[UIApplication sharedApplication] scheduleLocalNotification:theNotification];
}
Run Code Online (Sandbox Code Playgroud)
但是,这也没有做任何事情.
我希望在启动应用程序10秒后看到通知,但什么都没有出现.
另外,我在iPhone和模拟器上测试了这个.
我错过了一些非常关键的东西吗?(我搜索了Apple文档,找不到任何关于为什么会发生这种情况的信息)
谢谢
mpl*_*ert 43
UILocalNotifications仅在应用程序未运行(或在后台运行)时自动显示.如果应用程序正在运行和本地通知火灾UIApplicationDelegate的- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification方法被调用,系统不显示任何内容(也没有播放声音).如果要显示通知,请UIAlertView在委托方法中创建自己.
iba*_*boo 12
还有一件事,不要忘记显示是否允许推送查询,将以下代码添加到AppDelegate:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:settings];
}
}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
12578 次 |
| 最近记录: |