#Blog

Blog articles on programming and problems focused on iOS and some web. I also write stories on my travel and hiking pursuits outside my work.

sizeForItemAt of UICollectionView not working in Swift

by

There was a requirement where I was setting custom size for UICollectionViewCell. Custom size wasn’t dynamic but a static tall portrait ratio size. The effective way to set your own custom size is to call implement delegate method of protocol UICollectionViewDelegateFlowLayout:


func collectionView_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return estimatedCollectionSize
}

The problem:

UICollectionView was ignoring size instruction. It was sizing the cells to fit its content only.

CONTINUE READING


Password Laravel Personal/Password Access Client Not Found

by

We must have stumbled on Laravel’s passport sometime for creating authentication api’s for our mobile apps providing full OAuth2 server implementation.

This post uses Laravel 7.x. Our passport installation is


composer require laravel/passport “~9.0”

We will perform the migration where Passport migrations will create the tables our application needs to store clients and access tokens. It will also create Users table for us.


php artisan migrate

We also updated the driver to use passport in config/auth.php


‘api’ => [
            ‘driver’ => ‘passport’,
            ‘provider’ => ‘users’,
            ‘hash’ => false,
        ],

Now in our registration api example when we try to generate access token


$user->createToken(‘MyApp Password Grant Client’)->accessToken;

It gives error:


Auth driver [passport] for guard [api] is not defined.
Personal access client not found.

CONTINUE READING


Get Push Notification While App in Foreground iOS in Swift

by

If the application is running in the foreground, iOS won’t show a notification banner or alert. That is by design.

If we receive local or remote notifications while we app is running in the foreground, we’re responsible for passing the information to our users in an app-specific way. Where to handle and process such request?

userNotificationCenter(_:willPresent:withCompletionHandler:)

Asks the delegate how to handle a notification that arrived while the app was running in the foreground.

If your app is in the foreground when a notification arrives, the shared user notification center calls this method to deliver the notification directly to your app. If you implement this method, you can take whatever actions are necessary to process the notification and update your app. When you finish, call the completionHandler block and specify how you want the system to alert the user, if at all.

CONTINUE READING


Present Safari View Controller Modally instead of Push

by

When I launch safari view controller(SFSafariViewController) by way of present(_:animated:completion:) method, I do not get the default modal transition behaviour, instead the transition is that of push (sliding in from the right), as if I called pushViewController:animated:

SFSafariViewController

An object that provides a visible standard interface for browsing the web.
CONTINUE READING


Hike and Cooking Whole Chicken Roast at Bushcraft Campfire

by


Currently Corona semi-lockdown is active in our city where we cannot travel outside the state. I can hear far away tall-snow mountains whispering in my ear and I am unable to reach them. Hope is alive and soon I will see them again. Until then I was on lookout to search for quiet haven of nature near me that isn’t known to many people. To seek quiet heaven away from city - to forget about work and responsibility for a while, and get myself immersed in sounds of nature. As if mother nature heard my wish I found an information about a secret creek in dense jungle located in hills some 1 hour away from the city. I have been preparing and waiting for little bushcraft adventure and this opened an opportunity. It would be great hiking adventure with my first attempt in starting bushcraft.I made a plan for hiking to that place and cook a whole roast chicken in little bushcraft style on campfire near that creek. Winter has marked their arrival but it’s not fully cold yet - still have one more month to feel the chilly needles into skin. I woke up early morning and prepare fresh countryside chicken from local farm near-me. I made all the preparation of spice-mix, additional seasonings, grill plates, matchsticks, drinking water and my camera equipment. We were set to go.



Hike was an uphill trail with landslide prone path at the beginning. After 15 minutes forest started to grow and soon we had a thick foliage and beautiful canopy above our head. More deeper we went, and old aged trees start to make appearance with their majestic girth and thickness standing tall reaching sky. Beautiful blue wild flowers were jostling playfully with wind. All stress and worrisome was forgotten. We reached the mountain creek.

CONTINUE READING


Adding two numbers in macOS x86-64 Assembly - Part 2

by

This is the second part as continuation of series “My first x86-64 assembly in macOS”. Please read first part to view assembly language programming from the perspective of total beginner. I thought simple addition of two numbers in assembly could be the next simple step in progress to learn assembly language programming, covering declaration of variable(kinda), accessing them, adding them and printing them. Hoping to give some more insights on assembly language programming adventure. This post follows same spirit of exploring the findings and observation through perspective of total beginner. If any information provided seems wrong please email me with explanation so I could understand and rectify. Most of the concepts we did explored in first part of the series but I will try to do very short brief here too.

I am using Intel based Mac running Catalina. In future when arm based Mac comes out, then this series may need to be interpreted separately. I am using AT&T syntax throughout the series.

Important Note:

Following assembly code may not be optimised. This assembly code to calculate the sum of numbers is for simple learning of following concepts:
  • Declare and Initialise variables in assembly.
  • Access variables in assembly.
  • Perform addition on variables in assembly.
  • Print the sum of variables in assembly.

Let’s start

CONTINUE READING


English Names of Nepali Fruits

by



List of Fruits name in nepali and english


CONTINUE READING


How To Recover Password in Raspberry Pi

by

It has been 2 years since I worked on my raspberry pi. I was making an attempt to connect my raspberry pi from macbook via SSH.


ssh pi@192.168.x.x

It asked for password to connect and well…I don’t remember Password of raspberry pi anymore.

The default password on Raspberry Pi OS is raspberry. During fresh installation 2 years ago when I was enabling ssh I had changed default to my own password.

Please Note: I am using Jessie. The following instructions may not be valid anymore for newer version.

I tried the pi configuration utility tool. It allows you to change the password. But it also requires you to input current password to continue. It takes me back to start of the problem. After searching through various helpful instructions in forums I stumbled into very easy solution that didn’t require me to eject my SD Card, plug it in different computer and do change in files etc.

CONTINUE READING


How to Send Local Video to iMessage in Swift

by

This post assumes we have understanding about exporting to mp4 video. The use case example of the discussion exports a video and save it locally inside app’s folder: Document, Cache or Temporary. In my case I am doing some very basic composing of video and saving it to my temporary folder. I want to send this video or share it to my contacts through iMessage or MFMessageComposeViewController. Below is a brief idea on how I am exporting to mp4 video that saves in app’s temporary folder.


let exportURL = URL(fileURLWithPath: NSTemporaryDirectory())
          .appendingPathComponent("filename")
          .appendingPathExtension("mp4")
export.outputFileType = .mp4
export.outputURL = exportURL

export.exportAsynchronously {
  DispatchQueue.main.async {
    switch export.status {
    case .completed:
        print("success")
    default:
      print("Something went wrong during export.")
      print(export.error ?? "unknown error")
      break
    }
  }
}

Now, I found 2 easy effective ways to share or attach video to iMessage or MFMessageComposeViewController.

CONTINUE READING


How to get Deprecated keyWindow in Swift

by

Note: Discussion in this post assumes we are considering single window based scenario.

Sometimes I need to access the main window of my app to add some temporary views to it - making it appear forefront no matter at what depth of user’s navigation-flow I am in.

From old days of single window based app we have been using very convenient property handed to us: keyWindow

keyWindow
This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible() message.


guard let window = UIApplication.shared.keyWindow else {return}

It has been long time. Now this has been deprecated from iOS 13 onwards.

We have our windows accessible from windows array:


let window = UIApplication.shared.windows[0]

A free assumption would be that first window in array would be the main window of the app - being the root. We want the root window so that any view being added be directly on top for our given purpose here. It worked good until unexpected happened. First object did not give UIWindow but UITextEffectsWindow. I could not add my view on the top anymore - adding to UITextEffectsWindow didn’t work for curiosity.

CONTINUE READING


Recommended posts