Hyston blog
About • Archive • RSS

CoreBluetooth

March 13, 2018

In last post I wrote about bluetooth tracker app, that I have tried to create. The idea was to develop battery widget for iOS today’s screen, similar to standard one, just with one difference: it should show not only currently connected devices, but also keep track of previously synchronised.
I use AirPods every day, it’s very handy to always have a headphones in your pocket without need to unravel wires. They can play 3-4 hours by themselves, and charged then by case several times. The problem is that phone shows the battery level of case only when you open it and keep at least one ear piece inside, which in regular usage happened never. There is a LED inside, but with my poor eyesight I constantly got mixed up green with red on such small dot. Goal was to show last known battery status to all connected and previously connected devices, especially AirPods and their case. Work with Bluetooth in iOS is relatively simple and in detail described here. The Bluetooth framework called CoreBluetooth and to get battery level of surrounding devices you need to implement these steps:

Unfortunately, as I said, AirPods does not provide ability to connect them directly. May be I’m just missing some obvious point, but I have spend several hours trying to connect them, when in the end I decided to search in AppStore applications, that will find bluetooth devices nearby. None of them were able to provide more information, that I have found during debugging. I still think, that it should be possible somehow - AirPods can be connected to Android, after all, but after several wasted evenings I gave up. I have some more interesting ideas in mind.

tags:


Some updates

March 5, 2018

I have finally removed admin page from this blog. I have tried several times to add .Net Core Identity , but each time it seemed to me as a overkill option to add a lot of things just to block access to admin page. So, I have just kept it open (since nobody read this blog, after all), which is not a good solution after all.
Recently I have found FileSystemWatcher class, that allows detect changes on directory. Now I’m using it to keep track on posts, which are simply heap of .md files, that I can get access over ssh.

Strange thing, that I have found: on Startup class method Configure can take limited list of possible arguments and if you want to resolve your dependencies there, you have to pass IServiceProvider as a parameter and then resolve your classes from that container.

var fileParser = serviceProvider.GetService<IFileParserService>();

tags:


Too much

February 27, 2018

I have three pet projects. One of them is simple game for ios, another is bluetooth devices battery tracker, third one is this blog. I also participating now in .net core courses on microsoft academy and recently started free trial german course from babel. On my kindle I have in progress enthralling "Sapiens: A Brief History of Humankind" and enormous Steven King's "the Stand". I'm doing workouts and running at least 2 times a week. Also I'm trying to finish Civ V game party, keep track in Prey and, when I have time, watch "Brooklyn 9-9" and listen a dozen podcasts. Besides that, I have full time job, wife and kid, that requires full my attention , when they are nearby.
How did I cope with all this things? I'm not.

This hobby diversification lead to chaos and, really, I cant finish anything. I'm only at the beginning of trying to sort things up, but already have some thoughts.

This is overwhelming, definitely first world problem, but it's one of my biggest problem currently. Get things done, even if this thing is to finish blog post, that nobody will read or consume another game.
And I should cancel my netflix subscribtion, too.

tags:


2017

January 11, 2018

It’s mid of jan and it definetelly a time find some last year results. Gadget of the year? Airpods. And apple watch! They become the main way I’m interacting with my phone for the last time. Their simplicity (esp. airpods) and easy to use made them best apple product, that I have own since ipod shuffle.
airpods
Game of the year? The last station. Because of this game I have started to read Strugackij brothers again. And, despite it was Zelda and Switch release and hype year, The last station was the only one new game, that I have played in 2017.
The Last Station
Person of the year? My son. From nice small peace of meat, that can barelly hold his head, he upgraded to small cute human, which can run, tries to talk and explore the world around.
Misha
Technology of the year? .net core. I didnt know, that such thing even exist, I got rough idea, what is dot net one year ago and now I’m server developer and have blog, that is based on this. It’s rapidly evolving platform, although I’m not sure, that it is what I want to use as day to day tool until my retirement.

tags:


Swift weird protocols

December 10, 2017

What’s the difference between interface and abstract class? I have heard this question on almost every interview, when last time I have looked for a job. In Swift, protocols are very close to Java/C# interfaces, and the can’t contain implementations.

protocol IListener {
    
    var id : Int { get set }
    
    mutating func setId(newId : Int) {
        self.id = newId
    }
}

Here Xcode throws a error:
error: protocol methods may not have bodies

But, as it turns out, it is possible to make protocol extensions, and that extension can have implementation:

protocol IListener {
    
    var id : Int { get set }
}

extension IListener {
    
    mutating func setId(newId : Int) {
        self.id = newId
    }
}

I have no idea, why it is so.
Another strange protocol limitation is that, if it use self reference, it can be used only as a generic constraint. I.e., compilator deniedto compile this code:

protocol IListener : Hashable {

}

/* here some IListener implementation */

_ = Set<IListener> // error!

This is some strange things, that clearly demonstrated, that Swift is still in development mode. If extension protocol hack can be explained as some philosophy/architecture principle, but why protocol, that supposed to support hashing function, cannot be used as a container templat, is not clear for me.

tags: dev, swift


← Next Previous →