Ble Using Compose - android-jetpack-compose

Unresolved reference: REQUEST_ENABLE_BT
Type mismatch.
Required:
Activity
Found:
Intent
in this piece of code
val enableIntent = Actvity(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableIntent, REQUEST_ENABLE_BT)
please show me methods to enable bluetooth

Related

What does that code mean in exception error "Thread 3: EXC_BAD_ACCESS (code=2, address=0x16dbc7ff0)"?

I got a run time error during a debug run of my Xcode project for iOS. The project was running on an iPhone 8 device running iOS 15.5. I am using Xcode version 13.4.1 on a Mac Pro running macOS Monterey version 12.5.
The error message occurred at a line of code where I initialize a custom struct.
Thread 3: EXC_BAD_ACCESS (code=2, address=0x16dbc7ff0)
Here is my relevant code. The error message shows in red where GroupLocalCache is being initialized.
import Foundation
import CloudKit
// Wrap a CKRecordZone and its caches (each record type should have its records saved in the caches.
//
final class Zone {
let cloudKitZone: CKRecordZone
let caches = [BaseLocalCache]()
private var groupCache: GroupLocalCache
init(cloudKitZone: CKRecordZone, container: CKContainer, cloudKitDB: CKDatabase) {
self.cloudKitZone = cloudKitZone
self.groupCache = GroupLocalCache(container: container, cloudKitDB: cloudKitDB, cloudKitZone: cloudKitZone)
}
}
Here is the code for GroupLocalCache:
final class GroupLocalCache: BaseLocalCache {
let container: CKContainer
let cloudKitDB: CKDatabase
let zone: Zone
private var serverChangeToken: CKServerChangeToken?
private var groups = [Group]()
init(container: CKContainer, cloudKitDB: CKDatabase, cloudKitZone: CKRecordZone) {
self.container = container
self.cloudKitDB = cloudKitDB
self.zone = Zone(cloudKitZone: cloudKitZone, container: container, cloudKitDB: cloudKitDB)
super.init()
fetchChanges() // Fetching changes with a nil token to build up the cache.
}
}
BaseLocalCache is a modified version of the BaseLocalCache class that comes with CloudKitShare Xcode project from this Apple webpage: Sharing CloudKit Data with Other iCloud Users.
I want to look up what that "2" represents in the message where it says "code=2".
Other posts on stackoverflow* and Apple's Developer Forums for this same error address specific situations different than the error in my code.
I would like to know what the low level cause of the error is, so I need to know what those codes are that show up in exception error messages, since they tell what the real cause of exception error are in a lower level than answers to posts about exception errors commonly found.
I think I found documentation at one time for those codes at another source outside of Apple. It seems there are codes that are used by hardware manufacturers for "architectures" such as "arm64" and "armv7". I see those in Xcode project build settings.
Do I really need to know what each code as given in the error message represent?
I found this article at Apple's Developer Documentation:
Understanding the Exception Types in a Crash Report
I found this documentation on Apple's Exception Handling Framework in a search with Google: Exception Handling. I don't see what I need. This framework seems to be more than I need at this time.
You currently have an infinite loop of object creations. That's why you get a crash.
When crashing, do not hesitate to see the callstack, you should see it clearly.
The Zone initialization, calls a GroupLocalCache initialization, which calls a Zone initialization, which will call a GroupLocalCache initialization, etc.
So you need to change the logic on your objects.

Cast from 'TCHMessageType' to unrelated type 'String' always fails

I am using Twilio Chat Client SDK for iOS where I am getting this warning. How can I get rid of this warning in my XCode?
messageAdded message: TCHMessage
let msgType: String = message.messageType as! String
Twilio DOC: https://media.twiliocdn.com/sdk/ios/chat/releases/3.1.1/docs/Constants/TCHMessageType.html
Warning: Cast from 'TCHMessageType' to unrelated type 'NSString' always fails
Since this is just a warning not an error and my code compiles and run great but I don't want to push code with warnings to the production level.
Any help?
message.messageType is of type TCHMessageType which is an enum. Maybe you want to use message.messageType.text, which is an Int. If you want to save it as string, just change it to
let msgType: String = "\(message.messageType.text)"

Cannot implement Swift SSLCreateContext

I am new to iOS development, and am trying to implement an SSL connection to a custom port.
I found the code from this answer as the best/easiest implementation of a secure connection over a socket https://stackoverflow.com/a/30733961/2306428
However, I am getting these errors:
Use of unresolved identifier 'kSSLClientSide'
Use of unresolved identifier 'kSSLStreamType'
Use of unresolved identifier 'kSSLSessionOptionBreakOnClientAuth'
I have checked and I am running Swift version 2.1.1, using iOS 9.2 SDK and Xcode 7.2. I have even tried adding import Security but that has no effect.
What is the reason that these constants are not being found?
The line being tested is here: https://github.com/ksred/bank-ios/blob/master/Bank/TCPClient.swift#L209
Please use the identifiers declared in Swift:
if let sslContext = SSLCreateContext(kCFAllocatorDefault, SSLProtocolSide.ClientSide, SSLConnectionType.StreamType) {
SSLSetIOFuncs(sslContext, sslReadCallback, sslWriteCallback)
SSLSetConnection(sslContext, &socketfd)
SSLSetSessionOption(sslContext, SSLSessionOption.BreakOnClientAuth, true)
SSLHandshake(sslContext)
}

lldb inspection of swift variables within dynamic framework

I am unable to inspect variable state within dynamic frameworks in the lldb debugging console. I am able to inspect the same code when I add it to the main application. Why is this? Is there a workaround? Any ideas?
(lldb) po URLSessionDataTask
error: <EXPR>:1:1: error: use of unresolved identifier 'URLSessionDataTask'
URLSessionDataTask
^
I had the same situation. I could create a class instant of anything in the main app but nothing in the dynamic libraries, when it was Swift code.
(lldb) exp let $a = RustyAppInfo() //class from framework
error: <EXPR>:3:10: error: use of unresolved identifier 'RustyAppInfo'
Fix for me:
(lldb) expr -- import rusty_nails //framework name
(lldb) exp let $a = RustyAppInfo()
My lldb version: 902.0.79.7. Notice, lldb knew I was trying to write swift code. In an iOS app, where you have Swift and Objective-C code, I always find it useful to type:
(lldb) settings set target.language swift
Answer was inspired by LLDB (Swift): Casting Raw Address into Usable Type

error - opening session failed as protocol [name] is not declared

I'm trying to connect a heart rate monitor via bluetooth. I have the device's SDK.
When I instantiate an object of type HRMonitor - it's delegate prints connectionChanged
Probably connected and working fine.
But right after that I get the folowing output:
2013-04-10 11:36:00.409 TestHRMonitor[601:907] connectionChanged
2013-04-10 11:36:00.415 TestHRMonitor[601:907] ERROR - opening session
failed as protocol com.ssiamerica.ipulse is not declared in Info.plist
2013-04-10 11:36:00.417 TestHRMonitor[601:907] ERROR -
/SourceCache/ExternalAccessory/ExternalAccessory-213.3/EASession.m:-[EASession
dealloc] - 137 unable to close session for _accessory=0x1fd26e70 and
sessionID=65536
I only have .h,.a files.
Sorry, I know this is a newbe's question but:
Can anyone please explain more about this error, and how do I declare this protocol in Info.plist?
[EDITED]I've worked this out.
All I needed to do is:
1. Open info.Plist
2. Add a key "Supported external accessory protocol.
3. add to the key the value [name] that was stated inside the error description.
I've worked this out.
All I needed to do is:
Open info.Plist
Add a key "Supported external accessory protocol.
add to the key the value [name] that was stated inside the error description.

Resources