#Coding

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

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

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

How to Display Image in SKShapeNode

by

I have been using SKShapeNode extensively to draw quick graphics by filling them with CGPaths for quick visual debugging and making prototypes. For example I can create procedural mountains quickly with SKShapeNode. In early times of spritekit SKShapeNode didn’t have way to render images on it. We have fillTexture available now that allows texture to fill the shape.


let shapeNode = SKShapeNode()
shapeNode.fillTexture = SKTexture(imageNamed: “testImage")

But, Our SKShapeNode is displaying nothing.

Why is that?

CONTINUE READING

App crashing when saving photos from WKWebView

by

I stumbled upon a crash in my app. In my app I have a WKWebView that lets user access web. I tried saving image from a website by long pressing - general way we do in our iOS safari - and app crashed. This user experience behaviour of long pressing and saving image is very common.

The crash error is:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data.

CONTINUE READING

UIImagepicker controller allowsEditing not working

by

Using native image picker system is easy and solves everyday basic needs of most apps.

UIImagePickerController
A view controller that manages the system interfaces for taking pictures, recording movies, and choosing items from the user’s media library.

Here is an example code that lets user pick images from photo library:


pickerController = UIImagePickerController()
pickerController?.delegate = self
pickerController?.mediaTypes = [“public.image”]
pickerController?.sourceType = .photoLibrary
self.present(pickerController!, animated: true, completion: nil)

We need to implement delegate methods that provides us media info from which we can extract image in our case if available. Here is a code


func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    if let image = info[.originalImage] as? UIImage{
    }
}

info
A dictionary containing the original image and the edited image, if an image was picked; or a filesystem URL for the movie, if a movie was picked. The dictionary also contains any relevant editing information. The keys for this dictionary are listed in Editing Information Keys.

Our picked image resides inside the key .originalImage which is optional so if something went wrong then it will be nil.

Now, UIImagePickerController also supports basic crop. To activate crop we set the allowsEditing property to true. By default it is false.

CONTINUE READING

How to redirect HTTP to HTTPS in Elastic Beanstalk

by

I want to configure the web servers on my Elastic Beanstalk environment’s instances to redirect HTTP traffic to HTTPS.

I want to state what my beanstalk environment is:

  • Apache Web Server.
  • PHP 7.3
  • HTTPS listener well configured with certificate

I will use a flexible way to configure my environment using .ebextensions

According to documentation:
You can add AWS Elastic Beanstalk configuration files (.ebextensions) to your web application's source code to configure your environment and customize the AWS resources that it contains. Configuration files are YAML- or JSON-formatted documents with a .config file extension that you place in a folder named .ebextensions and deploy in your application source bundle.
CONTINUE READING

AWS Elastic Beanstalk Swap Environment Urls

by

AWS provides a feature to exchange or swap the CNAME between environments. Documentation says -

CNAME swap

Because AWS Elastic Beanstalk performs an in-place update when you update your application versions, your application can become unavailable to users for a short period of time. You can avoid this downtime by performing a blue/green deployment, where you deploy the new version to a separate environment, and then swap CNAMEs of the two environments to redirect traffic to the new version instantly. A blue/green deployment is also required when you want to update an environment to an incompatible platform version.

If I want to upgrade my elastic beanstalk platform from say - for example php 5.6 to php 7.1 - then unfortunately I cannot do it. It allows me to upgrade within 5.6 platform but not switch between major platforms. Only recommended way is to create new environment with major upgraded platform and then swap the environment urls. This way original environment url will still be pointed to my domain running new platform.

CONTINUE READING

Recommended posts