- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我厌倦了这样做。让我告诉你发生了什么事。我使用的是 iOS 9.0 和 Xcode 7.3.1。
情况一:
我已经像这样在 didFinishLaunchingWithOptions
中注册了本地通知设置。
let settings = UIUserNotificationSettings(forTypes: [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound] , categories: nil)
application.registerUserNotificationSettings(settings)
我的项目中有多个 Controller ,用户将按下其中一个中的一个按钮,我将通过调用 App Delegate
中的一个函数来安排通知。函数如下。
func activatingUserLocalNotification(timeIntervalSinceNow : NSDate?, alertBody : String, userInfo : [NSObject : AnyObject], region : CLRegion?)
{
let localNotification = UILocalNotification()
localNotification.fireDate = timeIntervalSinceNow
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.alertBody = alertBody
localNotification.region = region
localNotification.regionTriggersOnce = false
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.userInfo = userInfo
localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
现在我已经通过按下一个按钮设置了一个通知,它调用了上面的函数它成功地安排了通知。
我已经在所有这些方法中设置了断点。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
// Break Point
return true
}
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
// Break Point
}
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void) {
// Break Point
}
func application(application: UIApplication, didReceivelocalNotification notification: UILocalNotification)
{
// Break Point
}
当应用程序处于 Foreground
时等待一段时间,等待更多时间。没啥事儿。我认为该应用程序会启动通知,并且会调用其中一个方法,这样我就可以在应用程序内显示通知。但什么也没发生。
情况二:
现在我尝试了同样的方法,现在我通过转到另一个应用程序并使用它一段时间来最小化应用程序 [App is in Background state ]。现在通知正常启动了,就像我告诉过你的那样,我在几乎所有方法中都设置了断点,但当我单击通知时,没有一个方法被调用。但是它调用了 applicationWillEnterForeground
,如果没有 launchOptions
,这个方法该怎么办。
我已经为此奋斗了两天,对发生的事情一无所知。
推送通知在 [应用程序内部和外部] 都可以正常工作。
让我知道你的想法?请。
我如何从 Controller 调用此函数 activatingUserLocalNotification
。
func setLocalNotificationForDistance(id : String, name : String, location : CLLocationCoordinate2D, radius : Double)
{
let alertBody = "Hello \(name)"
let dict : [NSObject : AnyObject] = ["aps" : ["alert" : alertBody], “id” : id]
let region = CLCircularRegion(center: location, radius: radius, identifier: id)
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.activatingUserLocalNotification(nil, alertBody: alertBody, userInfo: dict, region: region)
}
应用委托(delegate)
//
// AppDelegate.swift
//
//
import UIKit
import FBSDKCoreKit
import SVProgressHUD
import Alamofire
import GoogleMaps
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
//MARK: Local Variables
var window: UIWindow?
static let UpdateRootNotification = "UpdateRootNotification"
static let ShowMainUINotification = "ShowMainUINotification"
//MARK: Application Life Cycle
// Did Finish Launching
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
let settings = UIUserNotificationSettings(forTypes: [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound] , categories: nil)
application.registerUserNotificationSettings(settings)
return true
}
// Foreground
func applicationWillEnterForeground(application: UIApplication) {
}
// Did Become Active
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
application.applicationIconBadgeNumber = 0 // clear badge icon
}
// Did Enter Background
func applicationDidEnterBackground(application: UIApplication) {
}
// Opened Via Shortcut
func application(application: UIApplication, performActionForShortcutItem
shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
}
// Continue User Activity
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity,
restorationHandler: ([AnyObject]?) -> Void) -> Bool {
return true
}
//MARK: Local Notification
func activatingUserLocalNotification(timeIntervalSinceNow : NSDate?, alertBody : String, userInfo : [NSObject : AnyObject], region : CLRegion?)
{
let localNotification = UILocalNotification()
localNotification.fireDate = timeIntervalSinceNow
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.alertBody = alertBody
localNotification.region = region
localNotification.regionTriggersOnce = false
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.userInfo = userInfo
localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
}
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void) {
}
func application(application: UIApplication, didReceivelocalNotification notification: UILocalNotification)
{
application.applicationIconBadgeNumber = 0
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
}
// MARK: Push Notification
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
if API.sharedInstance.isLoggedIn() {
NSUserDefaults.standardUserDefaults().setObject(deviceToken, forKey: "push_token")
NSUserDefaults.standardUserDefaults().synchronize()
API.sharedInstance.registerDeviceToken(deviceToken)
}
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
application.registerForRemoteNotifications()
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
EventTracker.trackEventWithCategory("APN", action: "Registraion", label: "Failed")
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
APNSManager.sharedInstance.handlePushNotification(userInfo)
}
//MARK: Open URL
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL:url,sourceApplication:sourceApplication,annotation:annotation)
}
}
最佳答案
这有点滑稽,但是改变一下:
func application(application: UIApplication, didReceivelocalNotification notification: UILocalNotification)
收件人:
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification)
注意大写的 L。来自文档:
此外:期望此委托(delegate)方法仅在您的应用处于事件状态时被调用。由于您的应用程序处于事件状态,因此在这种情况下不应显示任何通知。您可以使用 didReceiveLocalNotification 委托(delegate)方法来处理它。
关于ios - 永远不会调用 didReceivelocalNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39073696/
我知道 didReceiveLocalNotification 会触发两次。首先它会在触发本地通知时触发,然后在用户选择它时触发。 有什么方法可以知道 didReceiveLocalNotificat
如果用户禁用了我的应用程序的通知,是否会调用“didreceivelocalnotification”方法?我需要一种在特定日期调用方法的方法。即使用户不想看到通知,也应该调用该方法。有没有比本地通知
我正在尝试将我的应用程序设置为在从本地通知打开时打开特定页面。我已经设置了 didReceiveLocalNotification 来打印通知信息。这已经工作了几天,但我今天才注意到,当我从 xcod
我厌倦了这样做。让我告诉你发生了什么事。我使用的是 iOS 9.0 和 Xcode 7.3.1。 情况一: 我已经像这样在 didFinishLaunchingWithOptions 中注册了本地通知
我是 iOS 和 Cocoa 编程的新手,今天我想构建一个小型 iOS 应用程序来测试本地通知。通知工作正常,一切都像我预期的那样工作。我唯一的问题是,方法 application:didReceiv
我正在使用 UILocalNotification 问题是当我使用 scheduleLocalNotification 发布我的通知时,它永远不会触发 didReceiveLocalNotificat
我正在使用以下方式处理本地通知: - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotifi
问题: - (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotificati
我的问题是我收到本地通知,然后告诉我的一位 VC 更新其 UITableView。但是,表格 View 不会重新加载。我知道所有 if 语句检查都已通过并且正在运行代码。这最初让我相信这是一个线程问题
最近我在尝试创建一个闹钟,当我使用UILocalNotification时,出现了问题。当应用程序在后台时,它会显示一个横幅,但是当应用程序处于事件状态时,即使我使用了didReceiveLocalN
我正在 iOS 7.1 中开发一个包含 UILocalNotification 的应用程序。当我的通知出现时,它会转到 AppDelegate didReceiveLocalNotification
在我的应用程序中,永远不会调用方法 - (void)application:(UIApplication *)application didReceiveLocalNotification: (UIL
当我创建本地通知回调时,didReceiveLocalNotification 被触发。当我点击本地通知时会触发相同的回调。目前我正在通过检查来划分这两种情况 if ([UIApplication s
我正在使用 Objective-c 创建一个 UILocalNotification在我的 iPhone 应用程序中。我的目标是 iOS 8 并使用 XCode 6。 我的问题涉及处理 UILocal
我正在安排本地通知。它适用于 iOS 9.x,但自 iOS 10 以来 -(void)application:(UIApplication *)application didReceiveLocalN
我已经设置了一个本地通知,它会在一定的时间间隔内触发,当我点击横幅时会调用“didReceiveLocalNotification”。现在当我从后台删除应用程序时,当我在横幅上点击时通知会再次出现,但
我正在尝试让 UILocalNotification 计划启动或让我的应用程序进入前台。我知道委托(delegate)函数有 didReceiveLocalNotification,但我想在 View
当我的应用程序进入后台时,系统会自动调用 applicationDidEnterBackground 并在该方法中触发本地通知。但是 didReceiveLocalNotification: 方法没有
所以这就是交易...我需要一种方法来区分我收到的应用程序状态 UILocalNotification . 有一种情况我不明白。也就是说,当应用程序当前在前台运行并且用户拉下通知中心(iOS 5)时,应
大家好! 当我的应用程序处于前台时,我希望它在触发 DidReceiveLocalNotification 时显示警报。 我可以在 AppDelegate.swift 中添加警报来模拟本地通知,但问题
我是一名优秀的程序员,十分优秀!