In IOS, when the device is kept idle for some time, the screen turns off and the device enters sleep mode. It also enters sleep mode when we press the power button to turn the screen off.
In my application, I wanted to detect If the device has entered/exited the sleep mode. I have followed the below links but some of these ways like observing 'Darwin notifications' is no longer allowed by apple. Other ways consider the device being locked as sleep mode, which is not precisely correct.
Is there a way to correctly determine this? Please share the apple documentation links if this is possible.
https://stackoverflow.com/questions/14191980/detect-screen-on-off-from-ios-service/14208787#14208787
https://nemecek.be/blog/104/checking-if-device-is-locked-or-sleeping-in-ios
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have added an "App Intents Extension" target to my main application in macOS. This generated the below two files:
TWAppIntent.swift
import AppIntents
struct TWAppIntent: AppIntent {
static var title: LocalizedStringResource = "TWAppIntent"
static var parameterSummary: some ParameterSummary {
Summary("Get information on \(\.$TWType)")
}
// we can have multiple parameter of diff types
@Parameter(title: "TWType")
var TWType: String
func perform() async throws -> some IntentResult {
return .result(dialog: "Executed TWAppIntent.")
}
}
TWAppIntentExtension.swift
import AppIntents
@main
struct TWAppIntentExtension: AppIntentsExtension {
}
I m able to build the extension target and I my intent action is available in the shortcuts app. However, on launching a shortcut with the above created intent action. I m getting the below popups:
From what I understand, I m getting this error because I have not added my 'TWAppIntent' to the TWAppIntentExtension.swift file which is the entry point for the extension, but I could not find any documentation around how to add it. Can someone help on how to do it or Is there something else that I m doing wrong?
I have a public swift function with the below declaration :
public func InternalMain (_ pNumOfArgs : Int32, _ pCmdlineArgs : UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>) -> Int32 {..}
I need this function as public because I need to invoke in from a different library. But the above declaration produces an error in my generated swift header i.e '-swift.h' file because 'UnsafeMutablePointer<UnsafeMutablePointer?>' type cannot be represented in the swift generated header.
Can someone help how do I get past this. This is a class independent function and I tried using the '@nonobj' to prevent this from getting in the generated header but it still gives an error.
I was looking out for the error handling for rendering the Widgets(like UIButton, UIVIew etc) on the screen in iOS. I am painting the screen programmatically using swift.
Considering a simple Widget(like for say UIButton) when we try to create using its initializer and set some properties like 'setTitle' . These functions neither return any value upon success/failure nor in documentation they have mentioned about any exceptions which would be raised upon failure.
https://developer.apple.com/documentation/uikit/uibutton/settitle(_:for:)
So, how to do error handling here in this scenarios, in case the apis fail to due some reason, like memory issue? There must be some scenarios for these api failure.
I have a UIKit application and it contains multiple UI components like UIWindow, UIView, UIButton, etc. I wanted to perform error handling for different OS calls in my application.
For example, when creating a UIImage using init(named:) initialiser, the documentation clearly states that if the UIImage object cannot be created then the initialiser returns nil value.
However, there are other UI components like UIButton (or like UIView), which when created using init(frame:)
initialiser, the documentation does not mention for any return value.
I wanted to know how to identify If the UIButton initialisation has failed?
How is it that apple recommends should we handle these api's, If they fail to create a button. suppose If there is a case where it fails due to insufficient memory.
Or is it that apple guarantees the Api's never fail?Is there some exception that is throw? I wanted somewhat detailed answer to these questions.
I wanted to perform simulation in my application as a self tour guide for my user. For this I want to programatically simulate various user interaction events like button click, keypress event in the UITextField or moving the cursor around in the textField. These are only few examples to state, it can be any user interaction event or other events.
I wanted to know what is the apple recommendation on how should these simulations be performed? Is there something that apple offers like creating an event which can be directly executed for simulations. Is there some library available for this purpose?
Hi,
I am an absolute beginner at IOKit registry and have a usecase to obtain the device manufacturer name, device serial number and device USB vendor name progrmatically. I m able to obtain the same using ioreg command but I wanted to get these values within my program. Thanks in advance.
Device serial number:
ioreg -rd1 -c IOPlatformExpertDevice | grep 'IOPlatformSerialNumber'
Device manufacturer name:
ioreg -rd1 -c IOPlatformExpertDevice | grep 'manufacturer'
USB device vendor names:
ioreg -rd1 -c IOUSBHostDevice | grep "USB Vendor Name"
I have been using the Cpp-Swift Interoperability in Xcode15 for direct communication between Cpp and Swift code. It required a few Build settings changes for the Swift Compiler, creating clang modules(module map file) to access cpp code in swift, specifying module map path to the swift compiler etc.
I wanted to use this interoperability feature in my visual studio project which is using Cmake. I want to build via cmake, using Xcode generator.
Prior to Swift5.9, we were using a ObjC bridging header whose support was provided in the Cmake using the Xcode attribute flag 'XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER'. Similarly we were specifying the generated header using the attribute 'XCODE_ATTRIBUTE_SWIFT_OBJC_INTERFACE_HEADER_NAME'
I m not able to find similar Xcode attribute property flags for my Cmake to enable this interoperability. What are the changes that we need to make in the Cmake(using Xcode generator) for this new interoperability to work. Can someone help with this?
I m trying to create an xcode project with cpp-swift interoperability(introduced in xcode15) using cmake xcode generator. I m able to invoke cpp code in swift and vice-versa but when opening the project in xcode, the build setting for 'C++ and Objective-C Interoperability' is still set to 'C/Objective C' like in image below. I want to set it to 'C++/Objective-C++'.
I m using the below cmake for this:
.
.
add_library(cxx-support ./Sources/CxxSupport/Student1.cpp
./Sources/CxxSupport/Teacher.swift
)
#include the directory to access modulemap content
target_include_directories(cxx-support PUBLIC
${CMAKE_SOURCE_DIR}/Sources/CxxSupport)
target_compile_options(cxx-support PUBLIC
"$<$<COMPILE_LANGUAGE:Swift>:-cxx-interoperability-mode=default>"
)
.
.
I Have also tried the below in cmake, but it didn't work.
#set(SWIFT_OBJC_INTEROP_MODE "objcxx" CACHE STRING "")
#target_compile_options(cxx-support PUBLIC
#"SWIFT_OBJC_INTEROP_MODE=objcxx")
Any help on how this can be achieved?
I have a project where I m making direct swift calls from cpp as introduced in swift5.9. Below is my swift class whose method is being invoked on cpp.
import Foundation
public class MySwiftClass
{
public static func testInterop () -> Void {
NSLog("----------- hey --------")
}
}
I m able to successfully invoke 'testInterop()' in cpp with the above class, however if I add conformance to NSObject in the 'MySwiftClass' class, then the swift call fails with the error "No member named 'MySwiftClass' in namespace 'Module2'", where Module2 is my swift target.
I m not able to identify why is this happening. Any help?
I was going through this apple documention and it states, "By default, the generated header contains interfaces for Swift declarations marked with the public or open modifier", however, In my Xcode project, the public methods are not visible in the objective C code, and only the methods that are marked with @objc are visible. Is there some problem in my code or Is this a bug?
I have observed that some of the applications like xcode show a list of recently opened documents in their dock menu like in the image below. I wanted to show similar recently opened docs for my application but I not able to find any resource on how to achieve this. Can someone help on how to do this?
I had raised a support request in Apple DTS for an issue related to notification. I had a few iteration with the support team related to this but the problem remains unresolved. Everytime I send a response for what has been asked, it takes more than a week for the team to reply. This issue has been pending for over a month now and my work is blocked due to this. Can someone help me in getting a quick response or tell me how to reach the relevant people who can help me with this?
Here is my Case ID : 5269018
I have observed that in my application, Even If I set the QoS value of all the thread created to USER_INTERACTIVE, the OS is producing a warning "Thread running at User-Interactive QoS class waiting on a lower QoS thread running at Default QoS class. Investigate ways to avoid priority inversions".
I am aware that it is not right to set all threads as USER_INTERACTIVE QoS, but If we assume this case for once, then it means that the OS can dynamically change the QoS of the threads even if we are explicitly setting it. Is this the correct understanding?
Also, the main thread has QoS value USER_INTERACTIVE, then is it the case that its child threads will inherit the QoS value from the parent thread, If we are not setting any QoS for a pthread?
I have a project implementing new interop mechanism and I m able to successfully invoke swift class method directly from swift. However, when I try to invoke the swift extension method it produces an error :
No member named 'GetExtData' in 'InteropExtension::SwiftCode'
Below is my cpp code:
#include "CppSource.hpp"
#include "InteropExtension-Swift.h"
void CppSource::CppToSwiftCall()
{
// successfull call
InteropExtension::SwiftCode::GetClassData();
//Below call is causing error. Why is swift extension method not invoked?
InteropExtension::SwiftCode::GetExtData();
}
Below is my swift code:
import Foundation
public class SwiftCode {
public static func GetClassData () -> String
{
return "classMethod"
}
}
extension SwiftCode {
public static func GetExtData () -> String
{
return "ExtMethod"
}
}
Can someone helpout on why is the extension methods not being invoked, and how can I invoke it?