Is it possible to enable Bluetooth (with Discoverability on), using a button on macOS? Or enable it when an application opens? I've looked around online for a solution but everything directs towards iPhone and iOS Development rather than anything on the Mac side. Everything that is geared towards iOS also states that it is not possible on the mobile devices, but it is possible to display an alert notifying the user to turn on their Bluetooth to use their accessories. Is any alert type possible?
Edit: The closest I could get to this was opening the Bluetooth pane of the System Preferences programmatically.
It's a private API.
Add the following to your bridging header:
void IOBluetoothPreferenceSetControllerPowerState(int);
And call it with 1 to enable or 0 to disable:
func setBluetooth(on: Bool) {
IOBluetoothPreferenceSetControllerPowerState(on ? 1 : 0)
}
setBluetooth(on: true)
Don't forget to import IOBluetooth in your Swift file.
To get the current status use int IOBluetoothPreferenceGetControllerPowerState();
Related
Initially the person before me set up a screen observer so that whenever the page changes, setCurrentScreen is triggered to send a event and log the screen. Because we use a bunch of open containers to animate page opening, the screen observer doesnt get triggered. So I went through the app and added some setCurrentScreen for those that the screenObserver missed, and while there I also added some logEvents to see if people are using specific parts of the app.
The way I set enabled debug view was in xcode, going to Product -> Scheme -> Edit Scheme and adding -FIRAnalyticsDebugEnabled and -FIRDebugEnabled Edit scheme
After ticking both of the above (or just one or the other), only these events are being triggered then the app stops sending events. Completely. What am I missing? output
I cannot find another issue about this. I am using the same package name in the app and firebase, otherwise I would have no output. All other issues are talking about no output at all. I have tried to do this on simulator and on actual iPhone and they both yield the same result. I have also set up a android emulator and have an actual phone. Tried it on both and same result. The above screenshot is from iPhone as I am on Mac and more comfortable working on a iPhone.
i have set IS_ANALYTICS_ENABLED to true in the .plist file and this did not work
I have a bare-bones app to play with push notifications. I have the Notification Service Extension working. I can send a remote notification with an image URL and have it load.
I can't seem to get Notification Content Extension working. I've gone through multiple tutorials and they all say, just create a Notification Content Extension from the target menu and then inside the Notification Content Extensions Info.plist set the
UNNotificationCategory
to some string. Then when you push the notification, inside the "aps" json-block make sure to have category the same as UNNotificationCategory.
When I receive a notification, I try to swipe it down, left or right and nothing really happens. However, the service extension is working great.
I am using an iPhone 5 with ios 10 and XCode 8.0. I read that at one point only devices with 3d touch could view the content extension but that has since changed since xCode 8 is out of beta.
Any ideas? How can I go about debugging this? I've tried running the app with the Notification Extension selected and printing out stuff inside
didReceive
but am not having any luck.
Make sure to set the Extension's deployment target to the same as your Application target.
Please check if you set the category identifier in your UNMutableNotificationContent() For e.g.
let content = UNMutableNotificationContent()
content.categoryIdentifier = "awesomeNotification"
where "awesomeNotification" is the identifier for your UNNotificationCategory
Such problem. iOS Content Extension work fine with iPhone 5s, SE, iPad2mini, but doesn't work with iPhoine 5, 5c:
UNUserNotificationCenter.current().supportsContentExtensions is false on iPhoine 5, 5c
Despite what I read elsewhere on stackoverflow and online, expanding the push notification did not work on an iPhone 5 and IOS 10. I borrowed an iPhone 6+ and my code worked fine.
For me it was due to changing signing certificates. I was able to resolve it by:
Deleting the app (and all apps in app group)
Restarting phone
Quitting Xcode
Cleaning project
Running again
I'm trying to programmatically return to the home screen in an iOS8 App using Swift. I want to continue the application running in the background though. Any ideas on how to do this?
Thanks in advance for the help.
When an app is launched, the system calls the UIApplicationMain function; among its other tasks, this function creates a singleton UIApplication object. Thereafter you access the object by calling the sharedApplication class method.
To exit gracefully (the iOS developer library explicitly warns you not to use exit(0) because this is logged as a crash ) you can use:
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
For example, my app exits when the user shakes the device. So, in ViewController.swift:
override func motionEnded(motion: UIEventSubtype,
withEvent event: UIEvent?) {
if motion == .MotionShake{
//Comment: to terminate app, do not use exit(0) bc that is logged as a crash.
UIControl().sendAction(Selector("suspend"), to: UIApplication.sharedApplication(), forEvent: nil)
}}
Swift 4:
UIControl().sendAction(#selector(NSXPCConnection.suspend),
to: UIApplication.shared, for: nil)
Edit: It's worth mentioning that in iOS 12 there's a bug that will prevent network connectivity if the app is brought back from background after sending the suspend action.
For that you should use following code
import Darwin
exit(0)
To force your app into the background, you can legally launch another app, such as Safari, via a URL, into the foreground.
See: how to open an URL in Swift3
UIApplication.shared.open() (and the older openURL) are a documented public APIs.
If you set the exits-on-suspend plist key, opening another app via URL will also kill your app. The use of this key is a documented legal use of app plist keys, available for any app to "legally" use.
Also, if your app, for some impolite reason, continues to allocate and dirty large amounts of memory in the background, without responding to memory warnings, the OS will very likely kill it.
How about setting of info.plist?
You can set "Application does not run in background" true in info.plist with editor.
Or Add this lines with code editor.
<key>UIApplicationExitsOnSuspend</key>
<true/>
There is no way to "programmatically return to the home screen" except for crashing, exiting your program or calling unofficial API. Neither is welcome by Apple. Plus the Human Interface Guidelines are also covering this.
I am developing an iPhone app which uses Settings.bundle to let the user choose some options.
I have two questions regarding this:
How can I completely remove/hide some setting? (for instance if the app is running on iPhone 3G I want to hide settings regarding the compass)
How can I disable (fade) a setting? (for instance, I have two Toggle Switches and if the first is set to OFF the second one has no meaning and should be disabled)
You can't. Your app cannot dynamically influence what is shown in the Settings app.
I'm really bangin' my head because I can't find the way to show the soft keyboard when there's a bluetooth input device connected to the iPad. I made some search on the web and this is the result:
a question on stackoverflow with a very short answer How can I detect if an external keyboard is present on an iPad?
an application developed by erica sadun for the cydia env http://www.tuaw.com/2010/06/02/hacksugar-bringing-back-the-on-screen-keyboard/
Erica said that the trick is to answer to the system that "There's no hardware keyboard attached".
I tried to write a category for UIKeyboardImpl and I overrided:
- (BOOL)isInHardwareKeyboardMode {
DEBUG(#"is called");
return NO;
}
But until now I haven't obtained anything. The overrided method is called but there's no soft keyboard.
Erica also said the application works by dynamic linking but I don't know how can I accomplish it. I don't need to be in the AppStore because this is a private application so I don't bother about rejection.
Thanks in advance
Ok. Finally got it. Many thanks to David, Matthias and Enrico. Here are the steps:
import the private framework GraphicsServices
call GSEventSetHardwareKeyboardAttached(NO) inside the viewDidLoad
add a button that toggles the keyboard by calling
static void toggleKeyboard(UIKeyboardImpl * keyImpl){
if (UIKeyboardAutomaticIsOnScreen()) {
UIKeyboardOrderOutAutomatic();
} else {
UIKeyboardOrderInAutomatic();
}
I've found this function on http://code.google.com/p/btstack/wiki/iPhoneKeyboardHiding
Now I can take input from the soft keyboard and from the bluetooth device at the same time.
To get around it using the apple keyboard you hit the eject key. Perhaps you can implement an action that sends the eject keycode? I think iSSH has a feature where you can tap the onscreen keyboard icon to bring it up even when a bluetooth keyboard is connected.