uiapplication

Accessing `shared` variable of `UIApplication` from inside `share extension` in Swift

我的梦境 提交于 2020-12-08 08:02:41
问题 I need to execute my host app from inside an extension. In Objective-C I've used this: // Get "UIApplication" class name through ASCII Character codes. NSString *className = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned char []){0x55, 0x49, 0x41, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E} length:13] encoding:NSASCIIStringEncoding]; if (NSClassFromString(className)) { // A different way to call [UIApplication sharedApplication] id object = [NSClassFromString

Swift. URL returning nil

早过忘川 提交于 2020-06-13 19:03:27
问题 I am trying to open a website in my app, but for some reason one line keeps returning nil, heres my code: let url = URL(string: "http://en.wikipedia.org/wiki/\(element.Name)")! if #available(iOS 10.0, *) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } else { UIApplication.shared.openURL(url) } } It's the first line ( let url = URL... ) that keeps on returning this error: fatal error: unexpectedly found nil while unwrapping an Optional value. What should I do to fix

How to call completionHandler for performFetchWithCompletionHandler in Swift

自古美人都是妖i 提交于 2020-02-23 10:07:48
问题 how can I call the completion Handler for the background fetch in Swift. I do the following: func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { // Do something completionHandler (UIBackgroundFetchResultNoData) // This does not work :( return } Can you please help me? Thanks, Tobi 回答1: The enum case is UIBackgroundFetchResult.NoData , so the correct way is: completionHandler (UIBackgroundFetchResult.NoData) or

How to re-enable the idle timer in ios once it has been disabled (to allow the display to sleep again)?

筅森魡賤 提交于 2020-02-21 10:45:28
问题 I have figured out how to stop an iOS device from going to sleep (see below), but I am having troubles undoing that setting. According to the Apple Documentation, it should just be changing the value of the idleTimerDisabled property. But when I test this, it does not work. This is how I am initially stopping the device from going to sleep: //need to switch off and on for it to work initially [UIApplication sharedApplication].idleTimerDisabled = NO; [UIApplication sharedApplication]

How to re-enable the idle timer in ios once it has been disabled (to allow the display to sleep again)?

僤鯓⒐⒋嵵緔 提交于 2020-02-21 10:44:32
问题 I have figured out how to stop an iOS device from going to sleep (see below), but I am having troubles undoing that setting. According to the Apple Documentation, it should just be changing the value of the idleTimerDisabled property. But when I test this, it does not work. This is how I am initially stopping the device from going to sleep: //need to switch off and on for it to work initially [UIApplication sharedApplication].idleTimerDisabled = NO; [UIApplication sharedApplication]

iOS Background Fetch mode can be used to schedule some operation in the future that doesn't actually fetch remote data?

南楼画角 提交于 2020-01-14 01:56:06
问题 I'm doing an app that requires to reschedule local notification on daily basis. I'm aware about the repeatInterval property, but repetitioon here is like each 2 days etc. I've seen silent notifications, but they can be used only with push notifications and due to some requirements I can't use that approach. Now the app works on the hypothesis that the user will open the app quite enough to reschedule those notifications. This hypothesis is fine and we all agree that will work, but I will be

How to programmatically hide and show status bar in iOS 13?

做~自己de王妃 提交于 2020-01-11 13:23:30
问题 I have made following common method for hiding and showing again status bar. It works fine before iOS 13, but I am getting following crash while I run it for device having iOS 13 or greater. +(void)showStatusBar:(BOOL)show { UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"]; if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) { [[UIApplication sharedApplication] setStatusBarHidden:!show withAnimation

How implement scheduling event with post a message on fb

五迷三道 提交于 2020-01-05 04:42:10
问题 I am creating an application in which I have add a facility for post message on ur account. Now this facility I am adding an event for scheduling. With help of that user can write a message and post that later or on particular date and time. For this I used a local notification event which is generate on given date by user. But problem is that when notification generate then I have call a function which is used for post message on Facebook. For generate notification I have used this code: -

how to detect idle user in iphone-sdk

坚强是说给别人听的谎言 提交于 2020-01-02 07:16:28
问题 In my Application I want to call Logout Function if user is idle for certain amount of time how to accomplish this answer doesn't work for me iPhone: Detecting user inactivity/idle time since last screen touch if i subclass my app delegate class from UIApplication and implement - (void)sendEvent:(UIEvent *)event It gives me error *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'There can only be one UIApplication instance.' I can't find the other

Finding the rootViewController in iOS

喜欢而已 提交于 2020-01-01 04:37:27
问题 In ShareKit, the code needs to determine where the rootViewController is so it can show a modal view. For some reason, the code is failing in iOS 5: // Try to find the root view controller programmically // Find the top window (that is not an alert view or other window) UIWindow *topWindow = [[UIApplication sharedApplication] keyWindow]; if (topWindow.windowLevel != UIWindowLevelNormal) { NSArray *windows = [[UIApplication sharedApplication] windows]; for(topWindow in windows) { if (topWindow