Skip to content

Instantly share code, notes, and snippets.

View randhirraj3130's full-sized avatar

Randhir Raj randhirraj3130

View GitHub Profile
@randhirraj3130
randhirraj3130 / FacebookLogin.swift
Last active February 10, 2017 10:43
Facebook Login in swift 3.0
func FbLoginButton() {
if (FBSDKAccessToken.current() != nil)
{
// User is logged in, do work such as go to next view controller.
print("already login")
self.getFBUserData()
}else{
@randhirraj3130
randhirraj3130 / cropImage.swift
Created December 20, 2016 07:51
how to crop image in swift 3.0
extension UIView
{
func getCropedImage(frame: CGRect) -> UIImage
{
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0)
drawHierarchy(in: CGRect(x: -frame.origin.x, y:-frame.origin.y, width: self.bounds.size.width, height: self.bounds.size.height), afterScreenUpdates: true)
let snapshotImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return snapshotImage
}
@randhirraj3130
randhirraj3130 / GetUUID.js
Created December 20, 2016 07:57
How to generate system unique UUID
function uuid()
{
var char = '0123456789abcdef'.split('');
var uuid = [], rnd = Math.random, r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4'; // version 4
for (var i = 0; i < 36; i++)
{
@randhirraj3130
randhirraj3130 / BuildAndInstall.txt
Created December 20, 2016 12:02
how to build and install ios app
how to build xcode project
Here is some instruction to install app directly from mac. but only install those devices which provisioning profile is install in app.
Install App directly from Mac.
1. open your xcode project
2. click product tab
3. click archive
4. click export
5. select save for development deployment
6. click next button
7. select development team account
@randhirraj3130
randhirraj3130 / downloadImage.swift
Last active April 12, 2017 13:13
how to download images from the url and show in your image view in swift 3.0 and objective c
// swift code 3.0
func downloadImage(url: URL)
{
print("Download Started \(url)")
getDataFromUrl(url: url) { (data, response, error) in
guard let data = data, error == nil else { return }
//print(response?.suggestedFilename)
print(url.lastPathComponent)
@randhirraj3130
randhirraj3130 / LoginInstagram.swift
Created December 23, 2016 10:24
Instagram Login in swift 3.0
let clientID = "aef611af2a1e4806a7de8c0aca13daac"
let redirect_uri = "https://www.twistfuture.com/"
let getAccessToken = "https://api.instagram.com/oauth/authorize/?client_id=\(clientID)&redirect_uri=\(redirect_uri)&response_type=token"
self.InstagramWebViewLogin.loadRequest(NSURLRequest(url: NSURL(string:getAccessToken as String)! as URL) as URLRequest)
@randhirraj3130
randhirraj3130 / rorateview.swift
Last active February 4, 2017 07:36
how to rotate view in swift 3.0
// rotate imageview via 90 degree
myview.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2)
// rotate imageview via 180 degree
myview.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
// rotate imageview via 270 degree
myview.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2)
// totate iamge
func imageRotatedByDegrees(oldImage: UIImage,degrees: CGFloat) -> UIImage {
let size = oldImage.size
@randhirraj3130
randhirraj3130 / googleLogin.swift
Last active April 5, 2017 06:25
how to apply google login in my app
// call the delegate on button click
// call following delegate into your view controller
//GIDSignInUIDelegate,GIDSignInDelegate
// register your app and download the googleservices-info.plist
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().clientID = "58108526797-sen1e9fq0gnlicnkhb6krmflva86ie1k.apps.googleusercontent.com"
@randhirraj3130
randhirraj3130 / cheakPermission.swift
Created February 28, 2017 07:31
how to check PhotoLibraryPermission in swift 3.0
func checkPhotoLibraryPermission() {
let status = PHPhotoLibrary.authorizationStatus()
switch status {
case .authorized:
self.GetGalleryImage()
break
//handle authorized status
case .denied, .restricted : break
//handle denied status
@randhirraj3130
randhirraj3130 / LocalNotification.swift
Created March 27, 2017 12:44
how to apply local notification in swift 3
// add the following code in app delegate
import UserNotifications
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
} else {