Skip to main content

Posts

Cancellable Task with Dispatch Work Item | iOS | Swift

In some scenarios, we all want that the task we want to perform should be cancellable later on. For this kind of behaviour, we already have OperationQueue but the use of It seems difficult for beginners. Most of us didn't use OperationQueue so frequently and were only familiar with Grand Central Dispatch (GCD) . by performing UI operations in the main thread, Dispatch Group, etc. By the use of DispatachWorkItem , we can create some tasks that can be cancelled later on. Here is the example, let workItem = DispatchWorkItem {     // Here is our task     debugPrint ( "Task is to print some text..." ) } This is DispatchWorkItem containing a task to print something. To perform this task, we need to make use of DispatchQueue like this by adding delay if required. DispatchQueue . main . asyncAfter (deadline: . now () + . seconds ( 1 ), execute: workItem ) Here is the basic example to add a task and perform it using DispatchQueue. Now to cancel that we need to keep the referen
Recent posts

UIDatePicker with UserNotifications | iOS | Swift

Local Notifications The big problem with APNS is that it requires you to run a server somewhere that interacts with APNS to push a notification to a device. For applications that already have a client-server architecture such as an IM client this is no big deal. There are also a number of third parties who can provide a cost efficient service for small scale users who do not want the trouble of running their own server. However for many applications this is still way too complicated. This blog helps us in triggering the notification at specific time which is being selected by user in date picker. For that you have to take textField and two buttons. And don,t forget to edit AppDelegate method. import  UserNotifications   func  application( _  application:  UIApplication , didFinishLaunchingWithOptions launchOptions: [ UIApplicationLaunchOptionsKey :  Any ]?) ->  Bool  {          let  center =  UNUserNotificationCenter . current ()         center. reque

UIDatePicker Example with UIToolBar | iOS | Swift

UIDatePicker object use to select the date and time, The UIDatePicker class have multiple rotate wheels and take value from that wheel and give one object of UIDatePicker and to get date from UIDatePicker object. In this example, take one textFiled in which to open the datePicker using inputView. and adding toolbar in DatePicker. Add the UITextField Delegate and drag it to view controller also. Follow the below steps : Step 1 :   Adding one textFiled named  textField_Date in ViewController and give IBOutlet connection and delegate. also take one UIDatePicker variable. @IBOutlet weak var textField_Date: UITextField! var datePicker : UIDatePicker! Step 2 :  The function pickUpDate to create UIDatePicker with ToolBar.  func pickUpDate(_ textField : UITextField){ // DatePicker self.datePicker = UIDatePicker(frame:CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 216)) self.datePicker.backgroundColor = UIColor.white self.datePicker.datePicker

Local Notifications Sample App | iOS | Swift

The Apple Push Notification Service (APNS) was released way back in iOS 3.0. That was only just over a year ago but given the pace of development in the mobile OS market that now seems like ancient history. APNS was a first tentative attempt by Apple to address the demand for background processes. It allows client applications to receive updates from a server without having to be running. Apple takes care of pushing the notification to the device and the user can then decide whether to launch the application or not. Local Notifications The big problem with APNS is that it requires you to run a server somewhere that interacts with APNS to push a notification to a device. For applications that already have a client-server architecture such as an IM client this is no big deal. There are also a number of third parties who can provide a cost efficient service for small scale users who do not want the trouble of running their own server. However for many applications this is still wa