Is there a way to get facebook user friends birthday using iOS Facebook SDK? Also, I've tried to load user friends birthday from user events but I've only got the events, not birthdays.
Here is the code I've tried:
class ViewController: UIViewController {
let facebookReadPermissions = ["user_events"]
override func viewDidLoad() {
super.viewDidLoad()
if FBSDKAccessToken.currentAccessToken() != nil {
return
}
FBSDKLoginManager().logInWithReadPermissions(self.facebookReadPermissions, handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
if error != nil {
FBSDKLoginManager().logOut()
println(error)
} else if result.isCancelled {
FBSDKLoginManager().logOut()
println("cancelled")
} else {
var allPermsGranted = true
let perms = result.grantedPermissions as NSSet
let grantedPermissions = Array(result.grantedPermissions).map( {"\($0)"} )
for permission in self.facebookReadPermissions {
if !contains(grantedPermissions, permission) {
allPermsGranted = false
break
}
}
if allPermsGranted {
// Do work
println("all perm granted, success!")
let fbToken = result.token.tokenString
let fbUserID = result.token.userID
println(fbToken)
println(fbUserID)
self.getUserEvents()
} else {
println("failure")
}
}
})
}
func getUserEvents() {
if FBSDKAccessToken.currentAccessToken() != nil {
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "events"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if error == nil {
println(result)
println("----------------------")
println(result as! NSDictionary)
}
})
}
}
}
Output:
{
events = {
data = (
{
description = dfgfdgfdg;
id = 791086224356028;
name = "B party";
"rsvp_status" = attending;
"start_time" = "2015-08-30";
},
{
description = "\U0422\U0435\U0441\U0442";
id = 1624498701141585;
name = "\U0422\U0435\U0441\U0442";
place = {
id = 356733231072690;
location = {
city = Kirovohrad;
country = Ukraine;
latitude = "48.5046610418";
longitude = "32.2676611219";
zip = 250;
};
name = "\U0433. \U041a\U0438\U0440\U043e\U0432\U043e\U0433\U0440\U0430\U0434 , \U0423\U043a\U0440\U0430\U0438\U043d\U0430";
};
"rsvp_status" = attending;
"start_time" = "2015-08-30";
}
);
paging = {
cursors = {
after = TVRZAeU5EUTVPRGN3TVRFME1UVTROVG94TkRRd09URTRNREF3T2pFMk5UQTRORGc1TmpnME9EVTRNUT09;
before = TnpreE1EZAzJNakkwTXpVMk1ESTRPakUwTkRBNU1UZA3dNREE2TVRjMk9UQTRNVE0xTmpnM09UWXgZD;
};
};
};
id = 1569554686600399;
}
From Facebook api v2.0 onwards, all friend permissions have been removed. You cannot get a friend's birthday. Reference https://developers.facebook.com/docs/apps/changelog
Related
I am using NWListener, NWBrowser, and NWConnection for a local peer-to-peer discovery app. Because the vc with both the browser and listener initializes them both, I end up connecting with myself. The only way that I could think of to prevent that is to stop execution with a return statement if the connection.endPoint is equal to the device's endPoint eg.
listener?.newConnectionHandler = { (nwConnection) in
if nwConnection.endpoint == self.deviceEndpoint { return }
}
browser?.browseResultsChangedHandler = { (results, changes) in
for result in results {
if result.endpoint == self.deviceEndpoint { return }
}
}
How can I get the device's NWEndPoint?
vc:
var browser: PeerBrowser?
var listener: PeerListener?
override func viewDidLoad() {
super.viewDidLoad()
listener = PeerListener()
browser = PeerBrowser()
}
Listener:
class PeerListener {
var listener: NWListener?
var deviceEndpoint: NWEndPoint?
init() {
self.deviceEndpoint = ???
let tcpOptions = NWProtocolTCP.Options()
// ...
let params = NWParameters(tls: nil, tcp: tcpOptions)
params.includePeerToPeer = true
listener = try? NWListener(using: params)
listener?.service = NWListener.Service(name: "MyName", type: "_myApp._tcp")
listener?.stateUpdateHandler = { (newState) in ... }
listener?.newConnectionHandler = { (nwConnection) in
if nwConnection.endpoint == self.deviceEndpoint { return } // *** STOP EXECUTION HERE ***
// ...
}
}
}
Browser:
class PeerBrowser {
var browser: NWBrowser?
var deviceEndpoint: NWEndPoint?
init() {
self.deviceEndpoint = ???
let params = NWParameters()
params.includePeerToPeer = true
browser = NWBrowser(for: .bonjour(type: "_myApp_.tcp", domain: "local"), using: params)
browser?.stateUpdateHandler = { (newState) in ... }
browser?.browseResultsChangedHandler = { (results, changes) in
for result in results {
if result.endpoint == self.deviceEndpoint { return } // *** STOP EXECUTION HERE ***
// ...
}
}
}
}
The way i fixed this was to include a unique uid (like the current userId) in the message and when it's received I filter.
Send message:
let data = // whatever the data is the currentUID is sent along with it
let message = NWProtocolWebSocket.Metadata(opcode: .text)
let context = NWConnection.ContentContext(identifier: "send", metadata: [message])
connection.send(content: data, contentContext: context, isComplete: true, completion: .contentProcessed({ (error) in
if let error = error { return }
print("Successfully Sent: \(data.count) bytes")
}))
Receive message
connection.receive(minimumIncompleteLength: 1, maximumLength: 4200) { [weak self](data, context, isComplete, error) in
if let err = error { return }
if let data = data, !data.isEmpty {
// parse the data and if the uid in the data is equal to the current user's id then return
}
}
I have submitted my app for review, but apple team regularly rejecting my app and telling they are getting exception. but i have tried it in multiple device and i am not getting any exception. they are telling they are getting exception while entering otp. i have given crash report provided by apple team below.
func validateOTP() -> Void {
var strOTP = String(format: "%#%#%#%#", txtFieldFirst.text ?? "1",txtFieldSecond.text ?? "0",txtFieldThird.text ?? "1",txtFieldFourth.text ?? "0")
strOTP = strOTP.trimmingCharacters(in: .whitespaces)
print("OTP:",strOTP)
if strOTP.count == 4 {
if isServerReachable() {
var dict: [String : Any] = [:]
dict["mobile"] = Defaults().strUserMobileNumber
dict["otp"] = strOTP
dict["device_id"] = StringConstant.Device.Id
dict["registration_id"] = Defaults().strDeviceToken
dict["device_type"] = StringConstant.Device.DeviceType
SVProgressHUD.show()
if strLoginType == StringConstant.kUserTypeStudent {
CCAParserLayer.callStudentLogin(dict, handler: { strStatus, strMessage, dictResponse in
SVProgressHUD.dismiss()
if (strStatus == "YES") {
let json = JSON(dictResponse!)
Defaults().strUserType = StringConstant.kUserTypeStudent
Defaults().strStudentId = json["student_data"][0]["student_id"].stringValue
Defaults().strUserId = json["student_data"][0]["user_id"].stringValue
Defaults().strStudentName = json["student_data"][0]["student_name"].stringValue
Defaults().strStudentMobile = json["student_data"][0]["student_mobile"].stringValue
Defaults().isLoggedIn = true
self.performSegue(withIdentifier: "otpToStudentDashboard", sender: self)
}else{
self.showToastAlert(strMessage ?? StringConstant.kErrorMsg)
}
})
}else{
CCAParserLayer.callCoachLogin(dict, handler: { strStatus, strMessage, dictResponse in
SVProgressHUD.dismiss()
if (strStatus == "YES") {
let json = JSON(dictResponse!)
Defaults().strUserType = StringConstant.kUserTypeCoach
Defaults().strUserId = json["user_id"].stringValue
Defaults().isLoggedIn = true
self.performSegue(withIdentifier: "otpToCoachDashboard", sender: self)
}else{
self.showToastAlert(strMessage ?? StringConstant.kErrorMsg)
}
})
}
}else{
showToastAlert(StringConstant.kNoInternet)
}
}
}
You can find crash report here : https://iosapps-ssl.itunes.apple.com/itunes-assets/Purple123/v4/c8/b4/f4/c8b4f459-268d-9e4f-41dc-e1a1debd59eb/attachment-14470021504513854757crashlog-F30F5C6F-07C9-4CC4-8B64-F59D82FB8BE3.txt?accessKey=1589094390_3573176945688459523_oOvkQoPlbl9fPoJG1v1vK5NdJTucUtWucC9bizZwY9B4EZuopjhvtKxf1naNx4BtYBPHmq2Ea0IfZs6uAOK65demdPuIBJvsxNIPFfrYYRhSRFT8ltCRFGBdHI5M8WWPyiCP4eRCwPkGaVVgFFVibbGEpYk4eDyInD0EiVNTfc8rDwSroUxEhY%2BdhrzluHhCVRkaPC5aMqSVFmY%2BMvW9SyvdvqS3dYOCEUb509YanCazpFPm%2FXSgxoTQFlNvzOnY
I have memory issues, especially for the error
XPC connection interrupted
The screen is freezing for a few seconds..
So, I've been learning how to use the Instruments tools and try to fix this error. However, I've been trying to find the error in my code and it's apparently not the fault of my code but maybe the libraries?
As a result of this test, I've got some warnings (the purple ones):
Memory Issues (3 leaked types):
- 1 instance of _DateStorage leaked (0x10b1eb060)
- 1 instance of OS_dispatch_data leaked (0x10b0b1ac0)
- 1 32-byte malloc block leaked (x10b1eb040)
Could you tell me how to fix these warnings, knowing there is no backtrace available? Or how could I find somewhere that could tell me to fix those?
EDIT:
Thanks to Instrument tools, I found the function that caused the problem! So, I don't know if it is really about memory or Idk but here's the function!
The accurate and useful error I get is : "Closure #1 in closure #1 in MessagesTableViewController.getLastMessages"
I found here What is a closure #1 error in swift?, the error is probably caused by forced optional types. So, I am going to try to remove those.
func getLastMessages(cell: ContactMessageTableViewCell, index: IndexPath) {
// first, we get the total number of messages in chatRoom
var numberOfMessagesInChatRoom = 0
let previousCellArray = self.tableView.visibleCells as! [ContactMessageTableViewCell]
var index1 = 0
var messages = [JSQMessage]()
var sortedMessages = [JSQMessage]()
var messagesSortedByChatRooms = [String: [JSQMessage]]()
var doesHaveMessagesCount = false
var doesHaveSortedMessagesCount = false
let firstQuery = Constants.refs.databaseChats.queryOrderedByKey()
_ = firstQuery.observe(.childAdded, with: { [weak self] snapshot in
if let data = snapshot.value as? [String: String],
let id = data["sender_id"],
let name = data["name"],
let text = data["text"],
let chatRoom = data["chatRoom"],
!text.isEmpty
{
if let message = JSQMessage(senderId: id, displayName: name, text: text)
{
messages.append(message)
var arrayVariable = [JSQMessage]()
// we wanna get all messages and put it in the array corresponding to the chat room key
if messagesSortedByChatRooms[chatRoom] != nil { // if there is already the chatRoom key in dictionary
if let message1 = messagesSortedByChatRooms[chatRoom] {
arrayVariable = message1
}
arrayVariable.append(message)
messagesSortedByChatRooms[chatRoom] = arrayVariable
} else { // if there isn't the chatRoom key
arrayVariable.append(message)
messagesSortedByChatRooms[chatRoom] = arrayVariable
}
}
}
DispatchQueue.main.async {
// we have to sort messages by date
for (chatRoom, messagesArray) in messagesSortedByChatRooms {
var loopIndex = 0
var lastMessage: JSQMessage?
var array = [JSQMessage]()
for message in messagesArray { // we run through the messages array
array.removeAll()
loopIndex += 1
if loopIndex != 1 {
if message.date > lastMessage!.date {
array.append(message)
messagesSortedByChatRooms[chatRoom] = array
} else {
array.append(lastMessage!)
messagesSortedByChatRooms[chatRoom] = array
}
} else {
lastMessage = message
if messagesArray.count == 1 {
array.append(message)
messagesSortedByChatRooms[chatRoom] = array
}
}
}
}
if !doesHaveMessagesCount {
//doesHaveMessagesCount = true
// we have the number of chats in database
let secondQuery = Constants.refs.databaseChats.queryOrderedByPriority()
_ = secondQuery.observe(.childAdded, with: { [ weak self] snapshot in
if let data = snapshot.value as? [String: String],
let id = data["sender_id"],
let name = data["name"],
let text = data["text"],
let chatRoom = data["chatRoom"],
!text.isEmpty
{
if let message = JSQMessage(senderId: id, displayName: name, text: text)
{
index1 += 1
if chatRoom != nil {
if let unwrappedSelf = self {
if unwrappedSelf.sortedChatRoomsArray.contains(chatRoom) {
sortedMessages.append(message)
for (chatRoomKey, messageArray) in messagesSortedByChatRooms {
unwrappedSelf.lastMessages[chatRoomKey] = messageArray[0]
}
}
}
}
if let unwrappedSelf = self {
if index1 == messages.count && chatRoom != unwrappedSelf.roomName {
sortedMessages.append(JSQMessage(senderId: id, displayName: name, text: "no message"))
}
}
}
}
DispatchQueue.main.async {
if let unwrappedSelf = self {
if !doesHaveSortedMessagesCount {
//doesHaveSortedMessagesCount = true
if unwrappedSelf.sortedChatRoomsArray.indices.contains(index.row) {
if unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]] != nil {
if unwrappedSelf.lastMessagesArray.count != 0 {
let currentChatRoom = unwrappedSelf.sortedChatRoomsArray[index.row]
if unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]]?.text != "no message" {
if UUID(uuidString: unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]]!.text) == nil {
cell.contactLastMessageLabel.text = unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]]?.text
} else {
cell.contactLastMessageLabel.text = "New image"
}
} else {
cell.contactLastMessageLabel.text = ""
cell.contactLastMessageLabel.font = UIFont(name:"HelveticaNeue-Light", size: 16.0)
}
if unwrappedSelf.lastMessagesArray.indices.contains(index.row) {
if unwrappedSelf.lastMessagesArray[index.row] != unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]]?.text {
if unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]]?.senderId != PFUser.current()?.objectId {
if unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]]?.text != "no message" {
cell.contactLastMessageLabel.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)
}
var numberOfDuplicates = 0
for cell in previousCellArray {
if cell.contactLastMessageLabel.text == unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]]?.text {
numberOfDuplicates += 1
}
}
if numberOfDuplicates == 0 {
if unwrappedSelf.selectedUserObjectId != "" {
unwrappedSelf.changeCellOrder(index: index.row, selectedUserObjectId: unwrappedSelf.selectedUserObjectId, lastMessage: unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]]!.text)
} else {
unwrappedSelf.changeCellOrder(index: index.row, selectedUserObjectId: "none", lastMessage: unwrappedSelf.lastMessages[unwrappedSelf.sortedChatRoomsArray[index.row]]!.text)
}
} else {
unwrappedSelf.tableView.reloadData()
}
cell.activityIndicatorView.stopAnimating()
}
} else {
cell.contactLastMessageLabel.font = UIFont(name:"HelveticaNeue-Light", size: 16.0)
}
}
}
} else {
}
}
}
}
}
})
}
}
})
}
FINL EDIT: I put a closure inside of another closure so it created an infine loop ;)
I'm using Google Places API for iOS and can successfully retrieve nearby places and present the address as a string. What I'm trying to do is extract address components such as city to store in a database.
The documentation indicates a GMSPlace has an addressComponents property (an array), but I can't seem to figure how to use this property.
The code below provides sets the entire address to the text of a label, but I can't get beyond that:
Edit ---- added code that shows how I'm trying to access Address Components
venueLabel.isHidden = false
venueLabel.text = selectedPlace?.name
addressLabel.isHidden = false
addressLabel.text = selectedPlace?.formattedAddress
let addressComponents = selectedPlace?.addressComponents
for component in addressComponents! {
let city = component["city"] //Error Type GMSPaceAddressComponent has no subscript members
print(city)
}
A safe Swift 4.2 solution:
let name = place.addressComponents?.first(where: { $0.type == "city" })?.name
selectedPlace.addressComponents is a array of GMSAddressComponent which have 2 properties type and name.
In you case it will be like
for component in addressComponents! {
if component.type == "city" {
print(component.name)
}
}
GMSAddressComponent is a class not a dictionary or array that's you are getting this error.
Additional component types can be referred from the link.
Swift 4
var keys = [String]()
place.addressComponents?.forEach{keys.append($0.type)}
var values = [String]()
place.addressComponents?.forEach({ (component) in
keys.forEach{ component.type == $0 ? values.append(component.name): nil}
})
print(values)
For the latest Google Places API (July 2019) this is what could help you.
Actually, Google now putting a couple of types for each element. So the "type" is now deprecated and "types" is new filed.
You can do something like this:
for addressComponent in (self.mySelectedPlace?.addressComponents)! {
for type in (addressComponent.types){
switch(type){
case "country":
var country = addressComponent.name
case "postal_code":
var postCode = addressComponent.name
default:
break
}
}
}
It's working in Swift 5 and iOS 13.3
1. Create a function for showing GMSAutocompleteViewController
func googlePlacesSearchVC() {
let acController = GMSAutocompleteViewController()
acController.delegate = self
// Specify the place data types to return.
let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) |
UInt(GMSPlaceField.formattedAddress.rawValue) |
UInt(GMSPlaceField.addressComponents.rawValue))!
acController.placeFields = fields
// Specify a filter.
let filter = GMSAutocompleteFilter()
filter.country = "IN"
acController.autocompleteFilter = filter
acController.secondaryTextColor = .darkGray
acController.primaryTextColor = .lightGray
acController.primaryTextHighlightColor = .black
acController.tableCellBackgroundColor = .whiteThree
acController.tableCellSeparatorColor = .lightGray
// Display the autocomplete view controller.
present(acController, animated: true) {
let views = acController.view.subviews
let subviewsOfSubview = views.first!.subviews
let subOfNavTransitionView = subviewsOfSubview[1].subviews
let subOfContentView = subOfNavTransitionView[1].subviews
let searchBar = subOfContentView[0] as! UISearchBar
searchBar.searchTextField.placeholder = "places_picker_hint_add_address".localized
searchBar.searchBarStyle = .minimal
searchBar.searchTextField.font = UIFont.screenTitle16Pt
searchBar.searchTextField.backgroundColor = UIColor.white
searchBar.searchTextField.leftView?.tintColor = .darkGray
searchBar.delegate?.searchBar?(searchBar, textDidChange: "")
}
}
2. Call that function where ever you need, for ex:-
override func viewDidLoad() {
super.viewDidLoad()
googlePlacesSearchVC()
}
3. Call GMSAutoCompleteViewControllerDelegates Methods.
Here will get all details like Street, City, etc. from GMSPlace Address Components
extension ViewController {
// Handle the user's selection.
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
// Show HouseAndFlat
if place.name?.description != nil {
yourTxtField.text = place.name?.description ?? ""
}
// Show latitude
if place.coordinate.latitude.description.count != 0 {
var latitude = place.coordinate.latitude
}
// Show longitude
if place.coordinate.longitude.description.count != 0 {
selectedLongitude = place.coordinate.longitude
}
// Show AddressComponents
if place.addressComponents != nil {
for addressComponent in (place.addressComponents)! {
for type in (addressComponent.types){
switch(type){
case "sublocality_level_2":
yourTxtField.text = addressComponent.name
case "sublocality_level_1":
yourTxtField.text = addressComponent.name
case "administrative_area_level_2":
yourTxtField.text = addressComponent.name
case "administrative_area_level_1":
yourTxtField.text = addressComponent.name
case "country":
yourTxtField.text = addressComponent.name
case "postal_code":
yourTxtField.text = addressComponent.name
default:
break
}
}
}
}
dismiss(animated: true, completion: nil)
}
func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
// TODO: handle the error.
print("Error: ", error.localizedDescription)
}
// User canceled the operation.
func wasCancelled(_ viewController: GMSAutocompleteViewController) {
dismiss(animated: true, completion: nil)
}
}
I have found an answer from this link
I am using this extension:
extension Array where Element == GMSAddressComponent {
func valueFor(placeType: String, shortName: Bool = false) -> String? {
// bug in the google or apple framework. This cast must stay.
// Withou it crashing.
guard let array = self as? NSArray else { return nil }
let result = array
.compactMap { $0 as? GMSAddressComponent }
.first(where: {
$0.types
.first(where: { $0 == placeType }) == placeType
})
return shortName ? result?.shortName : result?.name
}
}
Usage:
let place: GMSPlace
// ...
place.addressComponents?.valueFor(placeType: kGMSPlaceTypeRoute, shortName: true)
I will extend #Ramis answer, in any case you want to check for multiple types if one of them exist, e.x
addressComponents?.valueFor(placeTypes: kGMSPlaceTypePostalTown, kGMSPlaceTypeLocality)
implementation
extension Array where Element == GMSAddressComponent {
func valueFor(placeTypes: String..., shortName: Bool = false) -> String? {
let array = self as NSArray
let result = array
.compactMap { $0 as? GMSAddressComponent }
.first(where: {
placeTypes.contains($0.types.first(where: { placeTypes.contains($0) }) ?? "")
})
return shortName ? result?.shortName : result?.name
}
}
I could not find this anywhere for Objective-C, for those who follow behind me:
for (int i = 0; i < [place.addressComponents count]; i++)
{
NSLog(#"name %# = type %#", place.addressComponents[i].name, place.addressComponents[i].type);
}
for ( GMSAddressComponent * component in place.addressComponents) {
if ( [component.type isEqual: #"locality"] )
{
NSLog(#"Current city %# ", component.name);
}
}
var keys = [String]()
place.addressComponents?.forEach{keys.append($0.type)}
var values = [String]()
place.addressComponents?.forEach({ (component) in
keys.forEach{ component.type == $0 ? values.append(component.name): nil}
print("All component type \(component.type)")
if component.type == "locality"{
print("This is city name \(component.name)")
}
})
print(values)
I found this, I hope I help you
let arrays : NSArray = place.addressComponents! as NSArray
for i in 0..<arrays.count {
let dics : GMSAddressComponent = arrays[i] as! GMSAddressComponent
let str : NSString = dics.type as NSString
if (str == "country") {
print("Country: \(dics.name)")
self.pais = dics.name
}
else if (str == "administrative_area_level_2") {
print("City: \(dics.name)")
self.ciudad = dics.name
}
print("City: (String(describing: place.addressComponents?.first(where: {$0.type == "locality"})?.name))")
print("Postal Code: (String(describing: place.addressComponents?.first(where: {$0.type == "postal_code"})?.name))")
print("State: (String(describing: place.addressComponents?.first(where: {$0.type == "administrative_area_level_1"})?.name))"
Use this description for work like this.
https://developers.google.com/maps/documentation/places/ios-sdk/place-data-fields
Hi am using CNContacts to fetch my contacts but takes around two minutes to display all the contacts in swift.Is there any way to speed up my Fetching time?
do
{
try store.enumerateContactsWithFetchRequest(request)
{ contact, stop in
contacts.append(contact)
}
}
catch
{
print(error)
}
for contact in contacts
{
let formatter = CNContactFormatter()
formatter.style = .FullName
if(((formatter.stringFromContact(contact))) != nil)
{
for phoneNumber:CNLabeledValue in contact.phoneNumbers
{
let number = (contact.phoneNumbers[0].value as! CNPhoneNumber).valueForKey("digits") as! String
let lable :String = CNLabeledValue.localizedStringForLabel(phoneNumber.label)
if (lable.containsString("mobile"))
{
if((contact.emailAddresses.isEmpty))
{
self.Allemail.addObject((""))
}
else
{
self.Allemail.addObject((contact.emailAddresses[0].value))
}
self.Contactname=NSString(format:"'%#'",(formatter.stringFromContact(contact))!)
let contactnumber=NSString(format:"'%#'",number)
self.ContactsDictionary.addObject(self.Contactname)
self.allNumbers.addObject(contactnumber as String)
}
}
for i in 0..<self.ContactsDictionary.count
{
if(i == 0)
{
self.jsonstring = "[{'Name':\(self.ContactsDictionary.objectAtIndex(i)),'Number':\(self.allNumbers.objectAtIndex(i))}"
}else
{
self.jsonstring = "\(self.jsonstring),{'Name':\(self.ContactsDictionary.objectAtIndex(i)),'Number':\(self.allNumbers.objectAtIndex(i))}"
}
}
self.jsonstring = "\(self.jsonstring)]"
}
}
self.contactupload()