Firebase Authentication gives us backend services to authenticate users with your app. It provides SDKs and ready-made UI libraries. It supports authentication using passwords, and other providers like Google, Facebook and Twitter, Github, and more.
iOS 10
Refined API Naming : Migrating to Swift 3!
Xcode 8.0 comes with a Swift Migrator tool that helps you migrate your project to Swift 3, or update it to work with Swift 2.3 and the new SDKs.
Apple simplified the screenshot submission process for iOS
Now it’s easier than ever to deliver your screenshots and app preview using iTunes Connect. Submit just one set of screenshots and one optional app preview per device family, and they will be used across device sizes and localizations.
If your app’s UI or behavior changes based on device size, or if you would like to include localized screenshots, you can use the new Media Manager to add custom screenshots. Learn more by watching What’s New in iTunes Connect from WWDC16.
iOS 10 New Frameworks
- CallKit
The CallKit framework (CallKit.framework) lets VoIP apps integrate with the iPhone UI and give users a great experience. Use this framework to let users view and answer incoming VoIP calls on the lock screen and manage contacts from VoIP calls in the Phone app’s Favorites and Recents views. - Intents
The Intents framework (Intents.framework) supports the handling of SiriKit interactions. - IntentsUI
The Intents UI framework (IntentsUI.framework) supports the creation of an Intents UI extension, which is an optional app extension that displays custom content in the Siri or Maps interfaces. - Messages
To develop an iMessage app, you use the APIs in the Messages framework (Messages.framework) and To create app extensions that interact with the Messages app, allowing users to send text, stickers, media files, and interactive messages. - Speech
Using the APIs in the Speech framework (Speech.framework), you can perform speech transcription of both real-time and recorded audio. - UserNotifications
User Notifications framework (UserNotifications.framework), which supports the delivery and handling of local and remote notifications. - UserNotificationsUI
User Notifications UI framework (UserNotificationsUI.framework) lets you customize the appearance of local and remote notifications when they appear on the user’s device. - VideoSubscriberAccount
Video Subscriber Account framework (VideoSubscriberAccount.framework) to help apps that support authenticated streaming or authenticated video on demand (also known as TV Everywhere) authenticate with their cable or satellite TV provider.
References :
Announcements from Apple’s WWDC 2016 keynote
Apple Special Event. June 13, 2016.
At WWDC lots of major announcements. iOS 10 is biggest release yet, with incredible features in Messages and an all-new design for Maps, Photos, and Apple Music. With macOS Sierra, Siri makes its debut on your desktop and Apple Pay comes to the web. The latest watchOS offers easier navigation and a big boost in performance. And the updated tvOS brings expanded Siri searches.
- watchOS 3
- tvOS
- macOS Sierra
- Siri for Mac
- Apple Pay in Web
- iOS 10
- Swift Playgrounds – iPad
Now, Go with flow of technology, let’s learn something new… 😉
Get Reactions from Timeline Post via Facebook Graph API – Swift – iOS
New version of SDK is 4.16.x(Swift) and Graph API Version is 2.8.
With the Graph API 2.6 Facebook has given support to fetch (read only) the Reactions on Timeline Posts.
Post is updated for iOS 10 and Swift 3
API documentation is available here.
Let’s learn how to get reactions from the post
Install pods
1 2 3 4 5 6 7 8 9 |
# Uncomment the next line to define a global platform for your project platform :ios, '9.0' target 'FBSwiftLogin' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for FBSwiftLogin pod 'FacebookCore' pod 'FacebookLogin' end |
Login with Facebook
I have already written a tutorial on Facebook Login.
Get Facebook Posts via Graph API
We can get the Facebook post via graph API : /me/posts for that we have to add user_posts permission with login.
1 2 3 4 5 6 7 |
func getFacebookUserPosts() { FBSDKGraphRequest(graphPath: "/me/posts", parameters: nil, httpMethod: "GET").start(completionHandler: { (connection, result, error) in if (error == nil){ print(result) } }) } |
Get Reactions from one of the Post
We can get the Facebook post reactions via graph API : /{post-id}/reactions. We have to pass parameters like fields and summary as described in getReactions function.
Note : Here I am writing sample for only first post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
func getFacebookUserPosts() { var strGraphPath : String = "" FBSDKGraphRequest(graphPath: "/me/posts", parameters: nil, httpMethod: "GET").start(completionHandler: { (connection, result, error) in if (error == nil){ print(result) let data = (result as! [String : Any])["data"] as! [[String : Any]] if(data.count > 0) { let strId = data[0]["id"] as! String strGraphPath = "/"+strId+"/reactions" self.getReactions(strGraphPath) } } }) } func getReactions(_ strGraphPath:String) { FBSDKGraphRequest(graphPath: strGraphPath, parameters: ["fields":"id, name, type", "summary":"total_count, viewer_reaction"], httpMethod: "GET").start(completionHandler: { (connection, result, error) in if (error == nil){ print(result) } }) } |
Response should be like
Type of reactions : NONE, LIKE, LOVE, WOW, HAHA, SAD, ANGRY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
{ data = ( { id = ACCOUNT_ID; name = "NAME"; type = HAHA; }, { id = ACCOUNT_ID; name = "NAME"; type = LIKE; } ); paging = { cursors = { after = REFERENCE_ID; before = REFERENCE_ID; }; next = "NEXT_REFERENCE_LINK"; }; summary = { "total_count" = 56; "viewer_reaction" = NONE; }; } |
#Like #Share #React 🙂 😛 😀
Happy coding 🙂
Use of Operator Overloading with Swift
I was just going through the Swift document and I found that Swift allow to overload the operator just like as C++ Language. Objective-C doesn’t allow to overload the operator.
As swift document we can also say “Operator Functions”.
Let’s Overload ^ (XOR Operator) to make Power of the value
Function Prototype :
Declare function prototype with left hand side value and right and side value.
1 2 |
func ^(lhs: Int, rhs: Int) -> Int { } |
Operations in the function :
To make the power of the value we have to apply following operations
1 2 3 4 5 6 7 8 9 10 11 12 |
func ^(lhs: Int, rhs: Int) -> Int { if(rhs == 0) { return 1 } else { var result = lhs for _ in 1 ..< rhs { result *= lhs } return result } } |
Let’s try to use with the operator :
1 2 3 |
let a = 2^2 //4 let b = 2^4 //16 let c = 3^3 //27 |
Happy Coding 🙂
How to create a wrapper for Alamofire and SwiftyJSON? Swift – iOS
This blogpost updated with Swift 3 – Xcode 8 – iOS 10 – Alamofire 4.0
I have posted a basic tutorial about Alamofire and SwiftyJSON How to use Alamofire and SwiftyJSON with Swift?
And some day before we have learned about Use of Blocks(Closures) or Completion Handlers with Function in Swift – iOS
Let’s combine both the topics to make a WRAPPER of Alamofire and SwiftyJSON.
How to use Alamofire and SwiftyJSON with Swift? – Swift 3 – iOS 10 – Xcode 8
Alamofire is an HTTP networking library written in Swift.
SwiftyJSON makes it easy to deal with JSON data in Swift.
Create your own Slider menu (Drawer) in Swift
This article is updated with Swift 4 – Xcode 9 – iOS 11
Why to use a library everytime?
Let’s create our own Slide Menu (Drawer) in Swift 4.
1. Create New Project in Xcode 9 with Swift Language
2. Design the Menu in UIViewController
Declaration of Variables and Protocols (Delegate) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
protocol SlideMenuDelegate { func slideMenuItemSelectedAtIndex(_ index : Int32) } class MenuViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { /** * Array to display menu options */ @IBOutlet var tblMenuOptions : UITableView! /** * Transparent button to hide menu */ @IBOutlet var btnCloseMenuOverlay : UIButton! /** * Array containing menu options */ var arrayMenuOptions = [Dictionary<String,String>]() /** * Menu button which was tapped to display the menu */ var btnMenu : UIButton! /** * Delegate of the MenuVC */ var delegate : SlideMenuDelegate? } |
Following method is for updating the Items in the Menu :
1 2 3 4 5 |
func updateArrayMenuOptions(){ arrayMenuOptions.append(["title":"Home", "icon":"HomeIcon"]) arrayMenuOptions.append(["title":"Play", "icon":"PlayIcon"]) tblMenuOptions.reloadData() } |
Following method is for click event and animation :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
@IBAction func onCloseMenuClick(_ button:UIButton!){ btnMenu.tag = 0 if (self.delegate != nil) { var index = Int32(button.tag) if(button == self.btnCloseMenuOverlay){ index = -1 } delegate?.slideMenuItemSelectedAtIndex(index) } UIView.animate(withDuration: 0.3, animations: { () -> Void in self.view.frame = CGRect(x: -UIScreen.main.bounds.size.width, y: 0, width: UIScreen.main.bounds.size.width,height: UIScreen.main.bounds.size.height) self.view.layoutIfNeeded() self.view.backgroundColor = UIColor.clear }, completion: { (finished) -> Void in self.view.removeFromSuperview() self.removeFromParentViewController() }) } |
3. Now we will create a Base UIViewController to use anywhere in the project which control the delegate of menu.
First we will create this 3 lines Drawer Icon via Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
func addSlideMenuButton(){ let btnShowMenu = UIButton(type: UIButtonType.system) btnShowMenu.setImage(self.defaultMenuImage(), for: UIControlState()) btnShowMenu.frame = CGRect(x: 0, y: 0, width: 30, height: 30) btnShowMenu.addTarget(self, action: #selector(BaseViewController.onSlideMenuButtonPressed(_:)), for: UIControlEvents.touchUpInside) let customBarItem = UIBarButtonItem(customView: btnShowMenu) self.navigationItem.leftBarButtonItem = customBarItem; } func defaultMenuImage() -> UIImage { var defaultMenuImage = UIImage() UIGraphicsBeginImageContextWithOptions(CGSize(width: 30, height: 22), false, 0.0) UIColor.black.setFill() UIBezierPath(rect: CGRect(x: 0, y: 3, width: 30, height: 1)).fill() UIBezierPath(rect: CGRect(x: 0, y: 10, width: 30, height: 1)).fill() UIBezierPath(rect: CGRect(x: 0, y: 17, width: 30, height: 1)).fill() UIColor.white.setFill() UIBezierPath(rect: CGRect(x: 0, y: 4, width: 30, height: 1)).fill() UIBezierPath(rect: CGRect(x: 0, y: 11, width: 30, height: 1)).fill() UIBezierPath(rect: CGRect(x: 0, y: 18, width: 30, height: 1)).fill() defaultMenuImage = UIGraphicsGetImageFromCurrentImageContext()! UIGraphicsEndImageContext() return defaultMenuImage } |
Delegate (Protocol) method call :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
func slideMenuItemSelectedAtIndex(_ index: Int32) { let topViewController : UIViewController = self.navigationController!.topViewController! print("View Controller is : \(topViewController) \n", terminator: "") switch(index){ case 0: print("Home\n", terminator: "") self.openViewControllerBasedOnIdentifier("Home") break case 1: print("Play\n", terminator: "") self.openViewControllerBasedOnIdentifier("PlayVC") break default: print("default\n", terminator: "") } } |
To open a view controller by identifier :
Set the Restoration Identifier and Storyboard Identifier. If current view is open then we will not open it once again for that we have to check via Restoration Identifier.
1 2 3 4 5 6 7 8 9 |
func openViewControllerBasedOnIdentifier(_ strIdentifier:String){ let destViewController : UIViewController = self.storyboard!.instantiateViewController(withIdentifier: strIdentifier) let topViewController : UIViewController = self.navigationController!.topViewController! if (topViewController.restorationIdentifier! == destViewController.restorationIdentifier!){ print("Same VC") } else { self.navigationController!.pushViewController(destViewController, animated: true) } } |
4. Now We will assign this drawer to any of the UIViewController
We have to use only one method to add drawer (slide menu) self.addSlideMenuButton()
1 2 3 4 5 6 7 |
import UIKit class HomeVC: BaseViewController { override func viewDidLoad() { super.viewDidLoad() addSlideMenuButton() } } |
Source Code is available at the Github AKSwiftSlideMenu
You can download for versions of Swift 2, Swift 3 or Swift 4. From Releases Tab at GitHub AKSwiftSlideMenu.
Check other blog posts about Swift
Happy Coding 🙂