Skip to content

Instantly share code, notes, and snippets.

View fahied's full-sized avatar

Muhammad Fahied fahied

  • Emirates Airlines
  • Dubai
View GitHub Profile
@fahied
fahied / apns-pem
Created December 12, 2016 11:46
Create pem file for apple push notifications
Development Phase:
Step 1: Create Certificate .pem from Certificate .p12
Command: openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
Step 2: Create Key .pem from Key .p12
Command : openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
Step 3: Optional (If you want to remove pass phrase asked in second step)
Command : openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem
@fahied
fahied / storyboard
Created December 12, 2016 13:33
Convert iPhone storyboard to iPad (Universal) storyboard
After some digging through the storyboard source code, it turns out that the iPad storyboard was copied from the iPhone storyboard. So, the question really became how do I convert an iPhone storyboard into an iPad storyboard?
The answer is surprisingly simple. I ran across this SO answer -- to convert an iPhone storyboard to an iPad storyboard, do the following:
From Xcode, right-click on the storyboard and choose Open As -> Source code
Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"
Right-click on the storyboard again and choose Open As -> iOS Storyboard
The storyboard will now show all views in the correct size.
@fahied
fahied / MyWKWebVC.Swift
Created January 10, 2017 06:46
WKWebView controller example with progress bar
//
// MyWKWebVC.Swift
// Example
//
// Created by Fahied on 04/01/2017.
//
import Foundation
import UIKit
import WebKit
@fahied
fahied / etag
Created May 28, 2017 08:01 — forked from kevindelord/etag
How to integrate Etag in Swift
let API_HEADER_FIELD_NONE_MATCH : String = "If-None-Match"
let API_HEADER_FIELD_ETAG : String = "Etag"
let API_REQUEST_SUCCESS : Int = 200
func ETagForURL(urlString: String) -> String? {
// return the saved ETag value for the given URL
return NSUserDefaults.standardUserDefaults().objectForKey(urlString) as String?
}
@fahied
fahied / hackerRank.swift
Last active July 4, 2017 06:14
HackerRank Read Input with Swift
//Read String array separated by new line character
func readInput () -> [String]{
let n: Int = Int(readLine()!)!
var strs = [String]()
(0...n-1).map { _ in
strs.append(readLine()!.lowercased())
}
return strs
}
@fahied
fahied / youtubeLandscape
Created July 12, 2017 09:27
iOS: Play youtube video in fullscreen when device orientation is landscape
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if window == self.window {
return .portrait
} else {
return .allButUpsideDown
}
}
@fahied
fahied / MultiLineButton.swift
Created April 9, 2019 14:06
Multi Line UIButton
import UIKit
class MultiLineButton: UIButton {
// MARK: - Init
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.commonInit()
@fahied
fahied / alert.swift
Created April 10, 2019 15:27
UIWindow Alert
func showAlert(message: String) {
let alert = UIAlertController(title: "Link", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
@fahied
fahied / AssetExtractor.swift
Created April 11, 2019 06:28
Get URL from Xcode asset catalogs
import UIKit
//It basically just gets image from assets, saves its data to disk and return file URL.
class AssetExtractor {
static func createLocalUrl(forImageNamed name: String) -> URL? {
let fileManager = FileManager.default
let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0]
let url = cacheDirectory.appendingPathComponent("\(name).png")
@fahied
fahied / symbolicateiOS.md
Last active December 15, 2019 11:20
Symbolicate iOS crash manually

Step 1: Use the following command in Terminal to find the dSYM on your Mac which build the app

mdfind "com_apple_xcode_dsym_uuids == 12345678-90AB-CDEF-1234-567890ABCDEF"

The string "12345678-90AB-CDEF-1234-567890ABCDEF" is the UUID string from the crash report reformatted to uppercase and 8-4-4-4-12 groups.

Step 2: Symobolicate Crash Report. Excute the following line before symbolicating