একটি নির্দিষ্ট স্থানীয় বিজ্ঞপ্তি মুছুন


92

আমি স্থানীয় বিজ্ঞপ্তির উপর ভিত্তি করে একটি আইফোন অ্যালার্ম অ্যাপ বিকাশ করছি।

একটি অ্যালার্ম মোছার পরে, সম্পর্কিত স্থানীয় বিজ্ঞপ্তি বাতিল করা উচিত। তবে স্থানীয় নোটিফিকেশনের অ্যারে থেকে কোনটি বাতিল করতে হবে তা আমি ঠিক কীভাবে নির্ধারণ করতে পারি?

আমি [[UIApplication sharedApplication] cancelLocalNotification:notification]পদ্ধতি সম্পর্কে সচেতন তবে এটি বাতিল করার জন্য কীভাবে আমি এই 'বিজ্ঞপ্তি' পেতে পারি?

উত্তর:


217

আপনি আপনার স্থানীয় বিজ্ঞপ্তির ব্যবহারকারীর ইনফোতে কীটির জন্য একটি অনন্য মান সংরক্ষণ করতে পারেন। সমস্ত স্থানীয় বিজ্ঞপ্তি পান, অ্যারের মাধ্যমে লুপ করুন এবং নির্দিষ্ট বিজ্ঞপ্তি মুছুন।

নিম্নরূপ কোড,

ওবিজে-সি:

UIApplication *app = [UIApplication sharedApplication];
NSArray *eventArray = [app scheduledLocalNotifications];
for (int i=0; i<[eventArray count]; i++)
{
    UILocalNotification* oneEvent = [eventArray objectAtIndex:i];
    NSDictionary *userInfoCurrent = oneEvent.userInfo;
    NSString *uid=[NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"uid"]];
    if ([uid isEqualToString:uidtodelete])
    {
        //Cancelling local notification
        [app cancelLocalNotification:oneEvent];
        break;
    }
}

সুইফট:

var app:UIApplication = UIApplication.sharedApplication()
for oneEvent in app.scheduledLocalNotifications {
    var notification = oneEvent as UILocalNotification
    let userInfoCurrent = notification.userInfo! as [String:AnyObject]
    let uid = userInfoCurrent["uid"]! as String
    if uid == uidtodelete {
        //Cancelling local notification
        app.cancelLocalNotification(notification)
        break;
    }
}

ব্যবহারকারীনোটিকেশন:

আপনি যদি ইউজারনোটিকেশন (আইওএস 10+) ব্যবহার করেন তবে কেবল এই পদক্ষেপগুলি অনুসরণ করুন:

  1. ইউজারনিটিফিকেশন সামগ্রী তৈরি করার সময়, একটি অনন্য শনাক্তকারী যুক্ত করুন

  2. সরানোপেনডিংটিফিকেশন অনুরোধগুলি (আইডেন্টিফায়ার সহ :) ব্যবহার করে নির্দিষ্ট মুলতুবি বিজ্ঞপ্তি সরান

  3. সরানডেলিভারডনোটিকেশন (আইডেন্টিফায়ার সহ :) ব্যবহার করে নির্দিষ্ট বিতরণ বিজ্ঞপ্তি সরান

আরও তথ্যের জন্য, UNUserNotificationsCenter


@ কিংফোফ্লিস, আপনি কি আমাকে সেখানে "uidtodelete" এ দিতে বলবেন। কারণ এটি আমার ক্ষেত্রে অঘোষিত।
ishhhh

@ ইশ একটি কঠোর মানটিকে সঠিকভাবে সামঞ্জস্য করুন .. আপনার এটি ঘোষণা করা উচিত এবং এটি মুছে ফেলার জন্য ইউডের মান সহ অন্তর্নিহিত করা উচিত
কিংফফ্লিস

@ কিংফফ্লিস, ইউআইডি সর্বদা এনএসএলগ.ডোন্ট কনওয়ে নালাগুলি দেখায় যে কীভাবে এটি থেকে মুক্তি পাবেন lease দয়া করে আমাকে সহায়তা করুন
h ই

@ ইশ আপনি স্থানীয় বিজ্ঞপ্তি তৈরি করার সময় ইউজারআইফো অভিধানে ইউইডির কোনও মান সংরক্ষণ করেছেন? আমি মনে করি আপনি এটি মিস করেছেন।
কিংফফ্লিস

@kingofBliss, "ইউআইডি" এটি আপনার নিজস্ব ভেরিয়েবলের একটি নাম, আপনি "নোটিফিকেশন" এর মতো কোনও উল্লেখযোগ্য নাম ব্যবহার করতে পারেন এবং এটির NSDictionaryসাথে সম্পর্কিত সত্তার আইডির মান সহ সংরক্ষণ করতে পারেন UILocalNotification। তারপরে আপনার কাস্টম ডেটা দিয়ে ডিকশনারিতে নোটিফিকেশন.ইউসারআইএনফো সম্পত্তি সেট করুন। এখন আপনি বিজ্ঞপ্তিগুলি পেয়ে গেলে সেই কাস্টম আইডি বা আপনার প্রয়োজন হতে পারে এমন আরও কিছু দিয়ে তাদের আলাদা করতে পারবেন।
IgniteCoders

23

অন্যান্য বিকল্প:

প্রথমত, যখন আপনি স্থানীয় বিজ্ঞপ্তি তৈরি করেন, আপনি ভবিষ্যতে ব্যবহারের জন্য এটি ব্যবহারকারী ডিফল্টে সঞ্চয় করতে পারেন, স্থানীয় বিজ্ঞপ্তি অবজেক্টটি সরাসরি ব্যবহারকারী ডিফল্টে সংরক্ষণ করা যায় না, এই বস্তুকে প্রথমে এনএসডাটা অবজেক্টে রূপান্তরিত করা দরকার, এবং তারপরে এতে NSDataসংরক্ষণ করা যেতে পারে User defaults। নীচে এর জন্য কোড দেওয়া আছে:

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:localNotif];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:[NSString  stringWithFormat:@"%d",indexPath.row]];

আপনি স্থানীয় বিজ্ঞপ্তি সংরক্ষণ এবং নির্ধারিত করার পরে, ভবিষ্যতে, প্রয়োজনীয়তা দেখা দিতে পারে যে আপনি আগে তৈরি করা কোনও বিজ্ঞপ্তি বাতিল করতে হবে, সুতরাং আপনি এটি ব্যবহারকারী ডিফল্ট থেকে পুনরুদ্ধার করতে পারেন।

NSData *data= [[NSUserDefaults standardUserDefaults] objectForKey:[NSString   stringWithFormat:@"%d",UniqueKey]];

UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSLog(@"Remove localnotification  are %@", localNotif);
[[UIApplication sharedApplication] cancelLocalNotification:localNotif];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:[NSString stringWithFormat:@"%d",UniqueKey]];

আশাকরি এটা সাহায্য করবে


ধন্যবাদ, আমি এটি প্রথম উপায়ে বাস্তবায়ন করেছি তবে আপনার উত্তরটিও সঠিক this আমি এটি বিবেচনায় নেব which আপনি দয়া করে বলতে পারেন কোনটি আরও দক্ষ? সহায়তার জন্য ধন্যবাদ :)
যোগী

4
@ যোগী: আপনি যদি প্রথম উত্তরের দিকে লক্ষ্য করেন, আপনি যদি স্থানীয় বিজ্ঞপ্তি বাতিল করতে চান তবে আপনাকে প্রতিবার লুপের জন্য দৌড়াতে হবে, তবে উপরের উত্তরে আপনাকে লুপের জন্য কোনও চালানোর দরকার পড়বে না, আপনি সরাসরি স্থানীয় বিজ্ঞপ্তিটি অ্যাক্সেস করতে পারেন এবং বাতিল করতে পারেন স্থানীয় বিজ্ঞপ্তি এবং ব্যবহারকারীর ডিফল্ট থেকে এটিকে সরিয়ে দিন, আমার উত্তর অনুসারে এটি আরও কার্যকর উপায়
iMOBDEV

@ জিগনেশব্রাহ্মখত্রি আপনার পদ্ধতি কার্যকর। ব্যবহারকারী যখন অ্যাপটি আনইনস্টল করবেন এবং এটি পুনরায় ইনস্টল করবেন তখন এটি ব্যর্থ হবে।
কিংফফ্লিস

কিংগফ্লিস, এই ক্ষেত্রে আমাদের সমস্ত বিজ্ঞপ্তি বাতিল করতে হবে, তাই না? সুতরাং আমি অনুমান করি যে এই সমাধানটি আরও দ্রুত। :)
সুফিয়ান

@ সুফিয়ান সমস্ত বিজ্ঞপ্তি বাতিল করার জন্য আরও দ্রুততর একটি উপায় রয়েছে [[ইউআইএএপ্লিকেশন শেয়ারড অ্যাপ্লিকেশন] বাতিলআলোলোকনোটফিকেশন]; ;)
কিংফফ্লিস

8

এখানে আমি কি করি।

আপনার বিজ্ঞপ্তি তৈরি করার সময় এটি করুন:

  // Create the notification

UILocalNotification *notification = [[UILocalNotification alloc]  init] ;



notification.fireDate = alertDate;
notification.timeZone = [NSTimeZone localTimeZone] ;
notification.alertAction = NSLocalizedString(@"Start", @"Start");
notification.alertBody = **notificationTitle**;
notification.repeatInterval= NSMinuteCalendarUnit;

notification.soundName=UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;

[[UIApplication sharedApplication] scheduleLocalNotification:notification] ;

এটি মুছতে চেষ্টা করার সময় এটি করুন:

 NSArray *arrayOfLocalNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications] ;

for (UILocalNotification *localNotification in arrayOfLocalNotifications) {

    if ([localNotification.alertBody isEqualToString:savedTitle]) {
        NSLog(@"the notification this is canceld is %@", localNotification.alertBody);

        [[UIApplication sharedApplication] cancelLocalNotification:localNotification] ; // delete the notification from the system

    }

}

এই সমাধানটি একাধিক বিজ্ঞপ্তিগুলির জন্য কাজ করবে এবং আপনার কোনও অ্যারে বা অভিধান বা ব্যবহারকারী ডিফল্ট পরিচালনা করবেন না। আপনি ইতিমধ্যে সিস্টেম নোটিফিকেশন ডাটাবেসে সংরক্ষণ করেছেন এমন ডেটা ব্যবহার করছেন।

আশা করি এটি ভবিষ্যতের ডিজাইনার এবং বিকাশকারীদের সহায়তা করবে।

ছেলেরা শুভ কোডিং! : ডি


আপনার উত্তর ভাগ করে নেওয়ার জন্য ধন্যবাদ তবে যদি আপনার সমস্ত বিজ্ঞপ্তিগুলির একই শরীর থাকে বা শরীরটি ব্যবহারকারীর কাছ থেকে নেওয়া হয় তবে এই যুক্তিটি কীভাবে কাজ করে that সেই ক্ষেত্রে ব্যবহারকারী একই শরীরকে একাধিক বিজ্ঞপ্তি দিতে পারে।
যোগী

@ যোগী, সতর্কতার মতো, আপনি প্রয়োজনীয় নোটিফিকেশন পেতে, বিজ্ঞপ্তি.ফায়ারেট চেক করতে পারেন। অভিকে একটি সাধারণ সমাধানের জন্য ধন্যবাদ। আপনার জন্য 1 টি উত্তর দিন
নাজিক

4
@ এনজিক: আলোচনায় আপনার আগ্রহের জন্য ধন্যবাদ। এটি তবুও ব্যবহারকারী একটি অ্যালার্ম অ্যাপ্লিকেশন হিসাবে একই আগুনের তারিখে দুটি বিজ্ঞপ্তি নির্ধারণ করতে পারে। কমপক্ষে এটি একটি পরীক্ষকের জন্য একটি পরীক্ষার কেস হতে পারে এবং এই সমাধানটি এখানে ব্যর্থ হতে দেখায়।
যোগী

@ যোগী, জ্ঞানী টেস্টিং, কেন নাকিসুরে কথা আমরা চেক যদি ([localNotification.alertBody isEqualToString: savedTitle] || [localNotification.firedate == কিছু]), যেহেতু একই তারিখের সঙ্গে দুই বিজ্ঞপ্তিগুলি বিভিন্ন alertBody থাকা উচিত
Nazik

কোনও বিজ্ঞপ্তি সনাক্ত করার জন্য alertBodyবা অপব্যবহার করবেন না fireDate; ব্যবহার userInfoএই করছেন, @KingOfBliss বিবরণ দ্বারা উত্তর হিসাবে জন্য ক্ষেত্রের ...
Severin

8

শিডিউল এবং দ্রুত সরানোর নোটিকেশন:

    static func scheduleNotification(notificationTitle:String, objectId:String) {

    var localNotification = UILocalNotification()
    localNotification.fireDate = NSDate(timeIntervalSinceNow: 24*60*60)
    localNotification.alertBody = notificationTitle
    localNotification.timeZone = NSTimeZone.defaultTimeZone()
    localNotification.applicationIconBadgeNumber = 1
    //play a sound
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.alertAction = "View"
    var infoDict :  Dictionary<String,String!> = ["objectId" : objectId]
    localNotification.userInfo = infoDict;

    UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
    static func removeNotification(objectId:String) {
    var app:UIApplication = UIApplication.sharedApplication()

    for event in app.scheduledLocalNotifications {
        var notification = event as! UILocalNotification
        var userInfo:Dictionary<String,String!> = notification.userInfo as! Dictionary<String,String!>
        var infoDict :  Dictionary = notification.userInfo as! Dictionary<String,String!>
        var notifcationObjectId : String = infoDict["objectId"]!

        if notifcationObjectId == objectId {
            app.cancelLocalNotification(notification)
        }
    }



}

4
কোনও বিজ্ঞপ্তি সনাক্ত করার জন্য alertBodyবা অপব্যবহার করবেন না fireDate; ব্যবহার userInfoএই করছেন, @KingOfBliss বিবরণ দ্বারা উত্তর হিসাবে জন্য ক্ষেত্রের ...
Severin

হ্যাঁ সতর্কতা একটি নোটিফিকেশনটি সনাক্ত করার জন্য ভাল বিকল্প নয়। আমি এটিকে ইউজারআইফোন
রোমান বার্জিজাক

6

আইএমওবিডিএভের সমাধান কোনও নির্দিষ্ট বিজ্ঞপ্তি (যেমন অ্যালার্ম মুছে ফেলার পরে) মুছে ফেলার জন্য পুরোপুরি কাজ করে তবে এটি বিশেষভাবে কার্যকর যখন আপনার ইতোমধ্যে কার্যকর হওয়া কোনও বিজ্ঞপ্তি নির্বাচিতভাবে সরানো দরকার এবং এখনও বিজ্ঞপ্তি কেন্দ্রে রয়েছেন on

একটি সম্ভাব্য পরিস্থিতিটি হ'ল: অ্যালার্মের জন্য বিজ্ঞপ্তি প্রকাশিত হয় তবে ব্যবহারকারী সেই বিজ্ঞপ্তিটিতে আলতো চাপ না দিয়ে অ্যাপ্লিকেশনটি খোলায় এবং সেই অ্যালার্মের সময়সূচিটি আবার তৈরি করে। আপনি যদি নিশ্চিত করতে চান যে প্রদত্ত আইটেম / অ্যালার্মের জন্য কেবলমাত্র একটি বিজ্ঞপ্তি বিজ্ঞপ্তি কেন্দ্রে থাকতে পারে, এটি একটি ভাল পদ্ধতির। এটি অ্যাপ্লিকেশনটি খোলার সাথে সাথে সমস্ত বিজ্ঞপ্তি মুছে ফেলার অনুমতি দেয় না, এটি কি অ্যাপ্লিকেশনটি আরও ভাল ফিট করে।

  • একটি স্থানীয় প্রজ্ঞাপন তৈরি করার পর, ব্যবহার NSKeyedArchiverযেমন সঞ্চয় করতে Dataমধ্যে UserDefaults। আপনি বিজ্ঞপ্তির ব্যবহারকারীর তথ্য অভিধানে যা সঞ্চয় করছেন তার সমান একটি কী তৈরি করতে পারেন। যদি এটি কোনও কোর ডেটা অবজেক্টের সাথে সম্পর্কিত হয় তবে আপনি এর অনন্য অবজেক্ট আইডি সম্পত্তি ব্যবহার করতে পারেন।
  • এটি দিয়ে পুনরুদ্ধার করুন NSKeyedUnarchiver। এখন আপনি বাতিললোকনোটিকেশন পদ্ধতি ব্যবহার করে এটি মুছতে সক্ষম হন।
  • UserDefaultsসেই অনুযায়ী কী আপডেট করুন ।

এখানে সমাধানের একটি সুইফট ৩.১ সংস্করণ রয়েছে (আইওএস 10 এর নিচে লক্ষ্যগুলির জন্য):

স্টোর

// localNotification is the UILocalNotification you've just set up
UIApplication.shared.scheduleLocalNotification(localNotification)
let notificationData = NSKeyedArchiver.archivedData(withRootObject: localNotification)
UserDefaults.standard.set(notificationData, forKey: "someKeyChosenByYou")

পুনরুদ্ধার করুন এবং মুছুন

let userDefaults = UserDefaults.standard
if let existingNotificationData = userDefaults.object(forKey: "someKeyChosenByYou") as? Data,
    let existingNotification = NSKeyedUnarchiver.unarchiveObject(with: existingNotificationData) as? UILocalNotification {

    // Cancel notification if scheduled, delete it from notification center if already delivered    
    UIApplication.shared.cancelLocalNotification(existingNotification)

    // Clean up
    userDefaults.removeObject(forKey: "someKeyChosenByYou")
}

আমার জন্য কাজ করেছেন। অন্যান্য সমস্ত পরামর্শ নয়, কারণ অ্যারেটি খালি রয়েছে।
মাকসিম নিয়াজেভ

আইওএস 10 এর জন্য কোনও ধারণা?
ডান্পে

4
@ ড্যান্প: এখানে "
সরবরাহিত

গৌণ মোডগুলির সাথে সুইফট 3 নিয়ে আমার জন্য কাজ করেছেন, যা এক্সকোড পরিচালনা করে।
beshio 16

@ বেশিও: মাথা উঁচু করার জন্য ধন্যবাদ আমি এর সিনট্যাক্স আপডেট করেছি।
Rygen

5

সুইফট 4 সমাধান:

UNUserNotificationCenter.current().getPendingNotificationRequests { (requests) in
  for request in requests {
    if request.identifier == "identifier" {
      UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: ["identifier"])
    }
  }
}   

4

সুইফট সংস্করণ, প্রয়োজন হলে:

func cancelLocalNotification(UNIQUE_ID: String){

        var notifyCancel = UILocalNotification()
        var notifyArray = UIApplication.sharedApplication().scheduledLocalNotifications

        for notifyCancel in notifyArray as! [UILocalNotification]{

            let info: [String: String] = notifyCancel.userInfo as! [String: String]

            if info[uniqueId] == uniqueId{

                UIApplication.sharedApplication().cancelLocalNotification(notifyCancel)
            }else{

                println("No Local Notification Found!")
            }
        }
    }

2

আপনি যেমন বিজ্ঞপ্তি নির্ধারণ করার সময় বিভাগ শনাক্তকারী সঙ্গে একটি স্ট্রিং রাখতে পারেন

        localNotification.category = NotificationHelper.categoryIdentifier

এবং এটি অনুসন্ধান করুন এবং এটির মতো প্রয়োজন হলে বাতিল করুন

let  app = UIApplication.sharedApplication()

    for notification in app.scheduledLocalNotifications! {
        if let cat = notification.category{
            if cat==NotificationHelper.categoryIdentifier {
                app.cancelLocalNotification(notification)
                break
            }

        }
    }

2

দ্রুত 3-শৈলী:

final private func cancelLocalNotificationsIfIOS9(){


//UIApplication.shared.cancelAllLocalNotifications()
let app = UIApplication.shared
guard let notifs = app.scheduledLocalNotifications else{
    return
}

for oneEvent in notifs {
    let notification = oneEvent as UILocalNotification
    if let userInfoCurrent = notification.userInfo as? [String:AnyObject], let uid = userInfoCurrent["uid"] as? String{
        if uid == uidtodelete {
            //Cancelling local notification
            app.cancelLocalNotification(notification)
            break;
        }
    }
}

}

আইওএস 10 ব্যবহারের জন্য:

    let center = UNUserNotificationCenter.current()
    center.removePendingNotificationRequests(withIdentifiers: [uidtodelete])

1

আপনি যে ইউআইএলোকালনোটিকেশন অবজেক্টটি পাস করেছেন cancelLocalNotification:তা কোনও মিলিত বৈশিষ্ট্যের সাথে বিদ্যমান ইউআইওলোকলনোটিকেশন বস্তুর সাথে মিলবে।

সুতরাং:

UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = @"foo";
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];

একটি স্থানীয় বিজ্ঞপ্তি উপস্থাপন করবে যা পরে এটি দিয়ে বাতিল করা যেতে পারে:

UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = @"foo";
[[UIApplication sharedApplication] cancelLocalNotification:notification];

4
ধন্যবাদ আমি মনে করি আপনি একটি নতুন বিজ্ঞপ্তি তৈরি করছেন এবং তারপরে এটি বাতিল করছেন। এটি আমার পূর্ব নির্ধারিত বিজ্ঞপ্তিতে কোনও প্রভাব ফেলবে না এবং এটি এখনও বরখাস্ত হবে।
যোগী

অ্যালার্টবিডি ব্যতীত এমন কোনও সম্পত্তি কি মিলবে যা সম্পত্তির সাথে মিলবে?
শামসুদ্দিন

1

আমি সুইফট 2.0 এ এই ফাংশনটি ব্যবহার করি:

  static func DeleteNotificationByUUID(uidToDelete: String) -> Bool {
    let app:UIApplication = UIApplication.sharedApplication()
    // loop on all the current schedualed notifications
    for schedualedNotif in app.scheduledLocalNotifications! {
      let notification = schedualedNotif as UILocalNotification
      let urrentUi = notification.userInfo! as! [String:AnyObject]
      let currentUid = urrentUi["uid"]! as! String
      if currentUid == uidToDelete {
        app.cancelLocalNotification(notification)
        return true
      }
    }
    return false
  }

@ কিংফফ্লিসের উত্তর থেকে অনুপ্রাণিত


0

পুনরাবৃত্ত অনুস্মারকগুলির জন্য (উদাহরণস্বরূপ আপনি চান 4 মিনিটের সময় সূর্যের দিকে, শনি এবং বুধের দিকে আপনার অ্যালার্ম জ্বালাতে চান, তারপরে আপনাকে 3 এলার্ম তৈরি করতে হবে এবং এনএসউইকক্যালেন্ডারউনিটের পুনরাবৃত্তিটি সেট করতে হবে)।

একবারে কেবলমাত্র অনুস্মারক তৈরি করার জন্য:

UILocalNotification *aNotification = [[UILocalNotification alloc] init];
                aNotification.timeZone = [NSTimeZone defaultTimeZone];
                aNotification.alertBody = _reminderTitle.text;
                aNotification.alertAction = @"Show me!";
                aNotification.soundName = UILocalNotificationDefaultSoundName;
                aNotification.applicationIconBadgeNumber += 1;

                NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
                NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSWeekCalendarUnit|  NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit | NSWeekdayCalendarUnit) fromDate: _reminderDate];

                [componentsForFireDate setHour: [componentsForFireDate hour]] ; //for fixing 8PM hour
                [componentsForFireDate setMinute:[componentsForFireDate minute]];

                [componentsForFireDate setSecond:0] ;
                NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];
                aNotification.fireDate = fireDateOfNotification;
                NSDictionary *infoDict = [NSDictionary dictionaryWithObject:_reminderTitle.text forKey:kRemindMeNotificationDataKey];
                aNotification.userInfo = infoDict;

                [[UIApplication sharedApplication] scheduleLocalNotification:aNotification];

পুনরাবৃত্তি অনুস্মারক তৈরি করার জন্য:

for (int i = 0 ; i <reminderDaysArr.count; i++)
                {

                    UILocalNotification *aNotification = [[UILocalNotification alloc] init];
                    aNotification.timeZone = [NSTimeZone defaultTimeZone];
                    aNotification.alertBody = _reminderTitle.text;
                    aNotification.alertAction = @"Show me!";
                    aNotification.soundName = UILocalNotificationDefaultSoundName;
                    aNotification.applicationIconBadgeNumber += 1;

                    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
                    NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSWeekCalendarUnit|  NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit | NSWeekdayCalendarUnit) fromDate: _reminderDate];


                    [componentsForFireDate setWeekday: [[reminderDaysArr objectAtIndex:i]integerValue]];

                    [componentsForFireDate setHour: [componentsForFireDate hour]] ; // Setup Your Own Time.
                    [componentsForFireDate setMinute:[componentsForFireDate minute]];

                    [componentsForFireDate setSecond:0] ;
                    NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];
                    aNotification.fireDate = fireDateOfNotification;
                    aNotification.repeatInterval = NSWeekCalendarUnit;
                    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:_reminderTitle.text forKey:kRemindMeNotificationDataKey];
                    aNotification.userInfo = infoDict;

                    [[UIApplication sharedApplication] scheduleLocalNotification:aNotification];
                }
            }

ফিল্টারিংয়ের জন্য আপনি এটি প্রদর্শন করতে অ্যারে।

-(void)filterNotficationsArray:(NSMutableArray*) notificationArray{

    _dataArray = [[NSMutableArray alloc]initWithArray:[[UIApplication sharedApplication] scheduledLocalNotifications]];
    NSMutableArray *uniqueArray = [NSMutableArray array];
    NSMutableSet *names = [NSMutableSet set];

    for (int i = 0 ; i<_dataArray.count; i++) {
        UILocalNotification *localNotification = [_dataArray objectAtIndex:i];
        NSString * infoDict = [localNotification.userInfo objectForKey:@"kRemindMeNotificationDataKey"];

        if (![names containsObject:infoDict]) {
            [uniqueArray addObject:localNotification];
            [names addObject:infoDict];
        }
    }
    _dataArray = uniqueArray;
}

অনুস্মারক সরাতে এমনকি এটি একবারে বা পুনরাবৃত্তি হয়েছিল:

- (void) removereminder:(UILocalNotification*)notification
{
    _dataArray = [[NSMutableArray alloc]initWithArray:[[UIApplication sharedApplication]scheduledLocalNotifications]];

    NSString * idToDelete = [notification.userInfo objectForKey:@"kRemindMeNotificationDataKey"];
    for (int i = 0 ; i<_dataArray.count; i++)
    {
        UILocalNotification *currentLocalNotification = [_dataArray objectAtIndex:i];
        NSString * notificationId = [currentLocalNotification.userInfo objectForKey:@"kRemindMeNotificationDataKey"];

        if ([notificationId isEqualToString:idToDelete])
            [[UIApplication sharedApplication]cancelLocalNotification:currentLocalNotification];
    }

    _dataArray = [[NSMutableArray alloc]initWithArray:[[UIApplication sharedApplication]scheduledLocalNotifications]];
    [self filterNotficationsArray:_dataArray];
    [_remindersTV reloadData];

}

0

আমি কিংফফ্লিসের উত্তরটি কিছুটা বাড়িয়েছি, আরও একটু সুইফট 2-এর মতো লিখেছি, কিছু অপ্রয়োজনীয় কোড সরিয়েছি এবং কিছু ক্র্যাশ গার্ডগুলিতে যুক্ত করেছি।

প্রজ্ঞাপনটি তৈরি করার সময় শুরু করার জন্য, আপনাকে অবশ্যই নিশ্চিত করতে হবে যে আপনি বিজ্ঞপ্তির ইউড (বা কোনও কাস্টম সম্পত্তি সত্যই) সেট করেছেন userInfo:

notification.userInfo = ["uid": uniqueid]

তারপরে, এটি মোছার সময়, আপনি এটি করতে পারেন:

guard
    let app: UIApplication = UIApplication.sharedApplication(),
    let notifications = app.scheduledLocalNotifications else { return }
for notification in notifications {
    if
        let userInfo = notification.userInfo,
        let uid: String = userInfo["uid"] as? String where uid == uidtodelete {
            app.cancelLocalNotification(notification)
            print("Deleted local notification for '\(uidtodelete)'")
    }
}

4
সুরক্ষার জন্য আপনি গার্ড-স্টেটমেন্ট গার্ডটি ব্যবহার করতে পারবেন অ্যাপ = ইউআইএপ্লিকেশন.শ্রেড অ্যাপ্লিকেশন () অন্যথায় অ্যাপ্লিকেশনটিতে শিডুয়েলড নোটিফের জন্য "মিথ্যা ফিরিয়ে দিন" ched ...} তারপরে আপনাকে এটিকে বাধ্যতামূলকভাবে লুপ-এ মোড়ানো দরকার না
troligtvis
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.