कहा जाता है मैं इसे करने से थक गया हूं। मैं आपको बताता हूं कि क्या हो रहा है। मैं आईओएस 9.0 & एक्सकोड 7.3.1 का उपयोग कर रहा हूं।didReceivelocalNotification को कभी भी
स्थिति 1:
मैं didFinishLaunchingWithOptions
इस तरह में स्थानीय सूचना सेटिंग के लिए पंजीकृत किया है।
let settings = UIUserNotificationSettings(forTypes: [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound] , categories: nil)
application.registerUserNotificationSettings(settings)
मैं अपने प्रोजेक्ट में कई नियंत्रकों है, उपयोगकर्ता इनमें से किसी एक में एक बटन दबाने की जाएगी और मैं 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
में है, कुछ और समय इंतज़ार किया। कुछ नहीं हुआ। मैंने सोचा कि ऐप अधिसूचना को उजागर करेगा और विधि में से एक को बुलाया जाएगा, ताकि मैं ऐप के अंदर अधिसूचना पेश कर सकूं। पर कुछ नहीं हुआ।
स्थिति 2:
अब मैं, एक ही कोशिश की है अब मैं एक दूसरे ऐप्स पर जा रहा है और कुछ समय के लिए उपयोग करने से ऐप्लिकेशन [पृष्ठभूमि राज्य में अनुप्रयोग है] को कम से कम। अब अधिसूचना ठीक से निकाल दी गई है, जैसा कि मैंने आपको बताया है कि मैंने लगभग सभी विधियों में ब्रेकपॉइंट्स सेट किए हैं, लेकिन जब मैंने अधिसूचना पर क्लिक किया तो उनमें से कोई भी नहीं बुलाया। लेकिन इसे applicationWillEnterForeground
कहा जाता है, launchOptions
के बिना इस विधि के साथ क्या करने वाला है।
दो दिनों से मैं इस के साथ लड़ रहा हूं, क्या हो रहा है इसके बारे में कोई जानकारी नहीं है।
पुश सूचनाएं वर्क्स ललित हालांकि [& अंदर बाहर अनुप्रयोग]।
मुझे अपने विचारों को जानने दो? कृप्या।
मैं इस फ़ंक्शन को 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)
}
अनुप्रयोग प्रतिनिधि
//
// 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)
}
}
कृपया अपने ऐप प्रतिनिधि स्विफ्ट फ़ाइल कोड को साझा करें। –
धन्यवाद, कृपया कोड को सक्रिय करें जो "सक्रिय करने वाला उपयोगकर्ता नामांकन" –