nsnotificationcenter

How can I act on Core Data iCloud sync notification when the app is in the background?

有些话、适合烂在心里 提交于 2019-12-05 13:01:28
I have an iOS app that uses Core Data with iCloud sync. The app is working perfectly and syncing across multiple devices. As part of my implementation my app is registered for the: NSPersistentStoreCoordinatorStoresDidChangeNotification This notification works perfectly with the app in the foreground, but what I would like to do is fire a local notification to let the user know that the iCloud data in the app has changed, whenever the app is in the background and a sync notification comes in. I was under the impression that iCloud Core Data syncing continued in the background, but I am having

How To set Custom repeat interval For Nslocal Notification…?

断了今生、忘了曾经 提交于 2019-12-05 08:11:43
i am New to iphone Development .I Am Trying To Use NslocalNotification In My Project I Need To Give Remeinder For Every 2Hours or For Every Two Days Or For Every Two Months Etc..Currently I am Using NslocalNotification Repeat Interval .But Its Working For Only Every Minute For Every Hour using Nscalender .... NSString *InterVal=[freQuencyArr objectAtIndex:index-2]; NSString *InterValType=[freQuencyArr objectAtIndex:index-1]; if(![InterVal isEqualToString:@"Every"]) { result=[InterVal intValue]; }else result=1; if([InterValType isEqualToString:@"Day"]){ notification.repeatInterval=

How to check internet connectivity in ios?

拟墨画扇 提交于 2019-12-05 08:07:51
问题 How can I check whether the app is connected to the internet or not? currently, I am using this code in my appdelegate.m file dispatch_queue_t connectivityThread = dispatch_queue_create("com.gm.kart.connectivity", NULL); dispatch_async(connectivityThread, ^{ while (true){ if([GMMConnectivity hasConnectivity]) NSLog(@"%@", @"connected"); else NSLog(@"Not connected"); usleep(10000000); } }); and when I click my login button I want to do a check whether the internet is connected or not using

How to detect switch between macOS default & dark mode using Swift 3

有些话、适合烂在心里 提交于 2019-12-05 07:54:49
I want to change my status bar app icon when the user switches from default to dark mode and vice versa (using Swift 3). Here’s what i have so far: func applicationDidFinishLaunching(_ aNotification: Notification) { DistributedNotificationCenter.default().addObserver(self, selector: #selector(darkModeChanged(sender:)), name: "AppleInterfaceThemeChangedNotification", object: nil) } ... func darkModeChanged(sender: NSNotification) { print("mode changed") } Unfortunately, it’s not working. What am I doing wrong? I'm using this Swift 3 syntax successfully: DistributedNotificationCenter.default

How NSNotification works

随声附和 提交于 2019-12-05 07:31:06
I understand what in Notification, poster and observer. But I am quite unable to understand how our app or OS understands and sends the flag/notification to the observer-class? What is the mechanism behind this? Your answer and help will be appreciated a lot. Thanks ID. Imagine the Notification Center as a dictionary which has keys of the notification names and values of the list of observers (and their specified action methods). When a notification is posted, the list of observers for that notification name is obtained and iterated. Each observer has its action method called with the

Is there a notification on iOS if a UIAlertView is shown?

China☆狼群 提交于 2019-12-05 07:12:30
Wondering if there is a notification available if a UIAlertView pops up? Background: my app asks the user for a PIN after a period of inactivity but I would like to prevent it if an alert is on screen. I don't want to go through my code and find all alerts and disable the PIN checker, instead a notification would be awesome. Any hope with NSNotification ? Krumelur Just found the answer. It is hidden in here: Can I get message when I show UIAlertView If you listen to the " UIWindowDidBecomeVisibleNotification " notification, it will also fire for your own alerts, not only for system alerts. For

singleton for location updating multiple views

北战南征 提交于 2019-12-05 04:39:31
问题 I want to update user location in ALL views, after the locateButton in the navbar is pressed in ANY view. I've started by creating a singleton. Location.h #import <Foundation/Foundation.h> #import <CoreLocation/CoreLocation.h> #import <MapKit/MapKit.h> @interface Location : NSObject <CLLocationManagerDelegate> @property (nonatomic, strong) CLLocationManager* locationManager; + (Location*)sharedSingleton; @end Location.m #import "Location.h" @implementation Location { CLLocationManager

kReachabilityChangedNotification is called multiple times

江枫思渺然 提交于 2019-12-05 04:05:51
I'm using the Reachability classes for checking when I got an internet connection en when it goes down. This is my code: IN VIEW DID LOAD: internetReachable = [Reachability reachabilityForInternetConnection]; [internetReachable startNotifier]; // check if a pathway to a random host exists hostReachable = [Reachability reachabilityWithHostname:@"www.google.com"]; [hostReachable startNotifier]; Then the notification method -(void) checkNetworkStatus:(NSNotification *)notice { // called after network status changes NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];

Detect rotation changes in iOS

谁说我不能喝 提交于 2019-12-04 23:19:00
I am making an iOS app that needs to do a little interface rearrangement upon rotation. I am trying to detect this by implementing - (void)orientationChanged:(NSNotification *)note , but this gives me notifications for when the device is face up or face down. I want a way to just get notified when the interface changes orientations. Since iOS 8, above methods were deprecated, and the proper way to handle and detect device rotation is: -(void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id )coordinator; To detect device orientation, you should (according to documentation):

Warning for iOS/iPhone users about duplicate NSNotification observations

对着背影说爱祢 提交于 2019-12-04 22:29:01
This isn't a question so much as a warning to others to save them some time. NSNotificationCenter on iOS 3/iPhone OS 3 (I'm assuming also Mac OS X and iOS 4) has the following behavior: If you register yourself multiple times for the exact specific notification, NSNotificationCenter will NOT recognize the redundancy and instead will fire off as many notifications to you as you've registered an observation for. This is almost never the behavior you want to see and is almost always accidental. Example: I want my view controller to receive notifications from a singleton network object when new