iOS8 UILocalNotification 不起作用
<p><p>我正在使用以下代码进行本地通知。但它不起作用。位置已成功更新并进入这些方法,但未触发通知。有什么想法吗?:</p>
<p>注意:当应用程序在后台时它可以工作,但在应用程序关闭时不工作。</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (){
];
}
[ cancelAllLocalNotifications];
// Override point for customization after application launch.
self.locationManager = [ init];
self.locationManager.delegate = self;
return YES;
}
-(void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
if (]) {
UILocalNotification *notification = [ init];
notification.alertBody = @"You are checked in";
notification.soundName = @"Default";
[ presentLocalNotificationNow:notification];
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您应该记住,通知仅在您的应用处于后台而不是前台时出现。如果您在前台,请执行 AppDelegate 的 <code>- application:didReceiveLocalNotification:</code> 并自行手动处理通知。</p>
<p><strong>UPD</strong></p>
<p>如果您的应用即使在后台也没有运行,您的代码将不会被执行。寻找 <a href="https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html" rel="noreferrer noopener nofollow">Background modes</a> (跟踪用户的位置部分)寻找可能的解决方案,以通过事件要求系统启动您的应用程序,即使当前它不在内存中</p></p>
<p style="font-size: 20px;">关于iOS8 UILocalNotification 不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/29004815/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/29004815/
</a>
</p>
页:
[1]