Outlook MAPI Message Class Metadata in Outlook 2016 - powershell
I've been looking all over and I can't seem to find anywhere that MS has this information documented. (This includes the MS documentation on MAPI message classes. This Super User answer elucidates what seems to be all of the standard Message Classes that are possible, but I haven't been able to find a list of the possible metadata that are associated with the Message Classes.
Does anyone know where I can find the metadata for each of the Message Classes as well as a possible brief (or detailed!) description of what the column means? Some of them are pretty obvious ("ReceivedDate", Start, etc.) but others are less obvious.
I've munged around with PowerShell and managed to find the following:
Schedule Meeting Request:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies ",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"AutoForwarded",
"DeferredDeliveryTime",
"DeleteAfterSubmit",
"ExpiryTime",
"FlagDueBy",
"FlagRequest ",
"FlagStatus",
"OriginatorDeliveryReportRequested",
"ReceivedTime",
"Recipients",
"ReminderSet",
"ReminderTime",
"ReplyRecipients",
"SaveSentMessageFolder",
"SenderName",
"Sent",
"SentOn",
"Submitted",
"Links",
"DownloadState",
"ItemProperties",
"MarkForDownload",
"IsConflict",
"MeetingWorkspaceURL",
"FlagIcon",
"AutoResolvedWinner",
"Conflicts",
"SenderEmailAddress",
"SenderEmailType",
"PropertyAccessor",
"ConversationID",
"SendUsingAccount",
"IsLatestVersion",
"RTFBody",
"RetentionExpirationDate",
"RetentionPolicyName",
"BodyFormat"
RSS:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"ExpiryTime",
"HTMLBody",
"ReceivedTime",
"SenderName",
"SentOn",
"Links",
"ItemProperties",
"BodyFormat",
"DownloadState",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"AutoResolvedWinner",
"Conflicts",
"SenderEmailAddress",
"SenderEmailType",
"PropertyAccessor",
"TaskSubject",
"TaskDueDate",
"TaskStartDate",
"TaskCompletedDate",
"ToDoTaskOrdinal",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReminderTime",
"IsMarkedAsTask",
"ConversationID",
"RTFBody"
Notes:
"Application",
"Class",
"Session",
"Parent",
"Body",
"Categories",
"Color",
"CreationTime",
"EntryID",
"GetInspector",
"Height",
"LastModificationTime",
"Left",
"MessageClass",
"Saved",
"Size",
"Subject",
"Top",
"Width",
"Links",
"DownloadState",
"ItemProperties",
"MarkForDownload",
"IsConflict",
"AutoResolvedWinner",
"Conflicts",
"PropertyAccessor"
Contact:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"Account",
"Anniversary",
"AssistantName",
"AssistantTelephoneNumber",
"Birthday",
"Business2TelephoneNumber",
"BusinessAddress",
"BusinessAddressCity",
"BusinessAddressCountry",
"BusinessAddressPostalCode",
"BusinessAddressPostOfficeBox",
"BusinessAddressState",
"BusinessAddressStreet",
"BusinessFaxNumber",
"BusinessHomePage",
"BusinessTelephoneNumber",
"CallbackTelephoneNumber",
"CarTelephoneNumber",
"Children",
"CompanyAndFullName",
"CompanyLastFirstNoSpace",
"CompanyLastFirstSpaceOnly",
"CompanyMainTelephoneNumber",
"CompanyName",
"ComputerNetworkName",
"CustomerID",
"Department",
"Email1Address",
"Email1AddressType",
"Email1DisplayName",
"Email1EntryID",
"Email2Address",
"Email2AddressType",
"Email2DisplayName",
"Email2EntryID",
"Email3Address",
"Email3AddressType",
"Email3DisplayName",
"Email3EntryID",
"FileAs",
"FirstName",
"FTPSite",
"FullName",
"FullNameAndCompany",
"Gender",
"GovernmentIDNumber",
"Hobby",
"Home2TelephoneNumber",
"HomeAddress",
"HomeAddressCity",
"HomeAddressCountry",
"HomeAddressPostalCode",
"HomeAddressPostOfficeBox",
"HomeAddressState",
"HomeAddressStreet",
"HomeFaxNumber",
"HomeTelephoneNumber",
"Initials",
"InternetFreeBusyAddress",
"ISDNNumber",
"JobTitle",
"Journal",
"Language",
"LastFirstAndSuffix",
"LastFirstNoSpace",
"LastFirstNoSpaceCompany",
"LastFirstSpaceOnly",
"LastFirstSpaceOnlyCompany",
"LastName",
"LastNameAndFirstName",
"MailingAddress",
"MailingAddressCity",
"MailingAddressCountry",
"MailingAddressPostalCode",
"MailingAddressPostOfficeBox",
"MailingAddressState",
"MailingAddressStreet",
"ManagerName",
"MiddleName",
"MobileTelephoneNumber",
"NetMeetingAlias",
"NetMeetingServer",
"NickName",
"OfficeLocation",
"OrganizationalIDNumber",
"OtherAddress",
"OtherAddressCity",
"OtherAddressCountry",
"OtherAddressPostalCode",
"OtherAddressPostOfficeBox",
"OtherAddressState",
"OtherAddressStreet",
"OtherFaxNumber",
"OtherTelephoneNumber",
"PagerNumber",
"PersonalHomePage",
"PrimaryTelephoneNumber",
"Profession",
"RadioTelephoneNumber",
"ReferredBy",
"SelectedMailingAddress",
"Spouse",
"Suffix",
"TelexNumber",
"Title",
"TTYTDDTelephoneNumber",
"User1",
"User2",
"User3",
"User4",
"UserCertificate",
"WebPage",
"YomiCompanyName",
"YomiFirstName",
"YomiLastName",
"Links",
"ItemProperties",
"LastFirstNoSpaceAndSuffix",
"DownloadState",
"IMAddress",
"MarkForDownload",
"IsConflict",
"AutoResolvedWinner",
"Conflicts",
"HasPicture",
"PropertyAccessor",
"TaskSubject",
"TaskDueDate",
"TaskStartDate",
"TaskCompletedDate",
"ToDoTaskOrdinal",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReminderTime",
"IsMarkedAsTask",
"BusinessCardLayoutXml",
"BusinessCardType",
"ConversationID",
"RTFBody"
Conversations:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"AlternateRecipientAllowed",
"AutoForwarded",
"BCC",
"CC",
"DeferredDeliveryTime",
"DeleteAfterSubmit",
"ExpiryTime",
"FlagDueBy",
"FlagRequest",
"FlagStatus",
"HTMLBody",
"OriginatorDeliveryReportRequested",
"ReadReceiptRequested",
"ReceivedByEntryID",
"ReceivedByName",
"ReceivedOnBehalfOfEntryID",
"ReceivedOnBehalfOfName",
"ReceivedTime",
"RecipientReassignmentProhibited",
"Recipients",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReminderTime",
"RemoteStatus",
"ReplyRecipientNames",
"ReplyRecipients",
"SaveSentMessageFolder",
"SenderName",
"Sent",
"SentOn",
"SentOnBehalfOfName",
"Submitted",
"[To]",
"VotingOptions",
"VotingResponse",
"Links",
"ItemProperties",
"BodyFormat",
"DownloadState",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"IsIPFax",
"FlagIcon",
"HasCoverSheet",
"AutoResolvedWinner",
"Conflicts",
"SenderEmailAddress",
"SenderEmailType",
"EnableSharedAttachments",
"Permission",
"PermissionService",
"PropertyAccessor",
"SendUsingAccount",
"TaskSubject",
"TaskDueDate",
"TaskStartDate",
"TaskCompletedDate",
"ToDoTaskOrdinal",
"IsMarkedAsTask",
"ConversationID",
"Sender",
"PermissionTemplateGuid",
"RTFBody",
"RetentionPolicyName",
"RetentionExpirationDate"
Tasks:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"ActualWork",
"CardData",
"Complete",
"Contacts",
"ContactNames",
"DateCompleted",
"DelegationState",
"Delegator",
"DueDate",
"IsRecurring",
"Ordinal",
"Owner",
"Ownership",
"PercentComplete",
"Recipients",
"ReminderTime",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ResponseState",
"Role",
"SchedulePlusPriority",
"StartDate",
"Status",
"StatusOnCompletionRecipients",
"StatusUpdateRecipients",
"TeamTask",
"TotalWork",
"Links",
"DownloadState",
"ItemProperties",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"AutoResolvedWinner",
"Conflicts",
"PropertyAccessor",
"SendUsingAccount",
"ToDoTaskOrdinal",
"ConversationID",
"RTFBody",
Calendar:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"AllDayEvent",
"BusyStatus",
"Duration",
"End",
"IsOnlineMeeting",
"IsRecurring",
"Location",
"MeetingStatus",
"NetMeetingAutoStart",
"NetMeetingOrganizerAlias",
"NetMeetingServer",
"NetMeetingType",
"OptionalAttendees",
"Organizer",
"Recipients",
"RecurrenceState",
"ReminderMinutesBeforeStart",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReplyTime",
"RequiredAttendees",
"Resources",
"ResponseRequested",
"ResponseStatus",
"Start",
"NetMeetingDocPathName",
"NetShowURL",
"Links",
"ConferenceServerAllowExternal",
"ConferenceServerPassword",
"ItemProperties",
"DownloadState",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"MeetingWorkspaceURL",
"AutoResolvedWinner",
"Conflicts",
"PropertyAccessor",
"SendUsingAccount",
"GlobalAppointmentID",
"ForceUpdateToAllAttendees",
"StartUTC",
"EndUTC",
"StartInStartTimeZone",
"EndInEndTimeZone",
"StartTimeZone",
"EndTimeZone",
"ConversationID",
"RTFBody",
"BodyFormat"
e-mail (IPM.Note):
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"AlternateRecipientAllowed",
"AutoForwarded",
"BCC",
"CC",
"DeferredDeliveryTime",
"DeleteAfterSubmit",
"ExpiryTime",
"FlagDueBy",
"FlagRequest",
"FlagStatus",
"HTMLBody",
"OriginatorDeliveryReportRequested",
"ReadReceiptRequested",
"ReceivedByEntryID",
"ReceivedByName",
"ReceivedOnBehalfOfEntryID",
"ReceivedOnBehalfOfName",
"ReceivedTime",
"RecipientReassignmentProhibited",
"Recipients",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReminderTime",
"RemoteStatus",
"ReplyRecipientNames",
"ReplyRecipients",
"SaveSentMessageFolder",
"SenderName",
"Sent",
"SentOn",
"SentOnBehalfOfName",
"Submitted",
"[To]",
"VotingOptions",
"VotingResponse",
"Links",
"ItemProperties",
"BodyFormat",
"DownloadState",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"IsIPFax",
"FlagIcon",
"HasCoverSheet",
"AutoResolvedWinner",
"Conflicts",
"SenderEmailAddress",
"SenderEmailType",
"EnableSharedAttachments",
"Permission",
"PermissionService",
"PropertyAccessor",
"SendUsingAccount",
"TaskSubject",
"TaskDueDate",
"TaskStartDate",
"TaskCompletedDate",
"ToDoTaskOrdinal",
"IsMarkedAsTask",
"ConversationID",
"Sender",
"PermissionTemplateGuid",
"RTFBody",
"RetentionPolicyName",
"RetentionExpirationDate"
The Microsoft Outlook object browser displays the classes, properties, methods, and events available from the Outlook object library.
If you do not see the Developer tab, see Run in Developer Mode in Outlook to activate the Developer tab. On the Developer tab, in the Form group, click View Code to open the Script Editor. In the Script Editor, click Object Browser on the Script menu or press F2.
All of the available Outlook objects are listed in the Classes pane of the object browser in alphabetical order. To view the members of an object, select the object in the Classes pane. The members of this object appear in alphabetical order in the Members of pane. The heading at the top of this pane will reflect the name of the object that you select. For example, if you select the AppointmentItem object in the Classes pane, the heading of the Members of pane will appear as Members of AppointmentItem.
The interfaces and members of the Microsoft.Office.Interop.Outlook namespace that provide support for interoperability between the COM object model of Outlook and managed applications that automate Outlook are described here.
Related
How to operate on value in Create CSV step of Logic App?
I need to multiply the max_pay__c item in a record by 0.95 before including it in CSV table. What is the best method for that? I've tried using ... #mul(item()?['max_pay_c'],0.95) ... function, but that seems to use NULL for item()?['max_pay_c'] These are the first few records from "Get records" : { "body": { "value": [ { "#odata.etag": "", "ItemInternalId": "ccbce48a-cf62-4e3f-bd56-94b90764e1ca", "Delivery_ScheduledEndDateTime__c": "2023-01-30T18:00:00Z", "Delivery_ScheduledStartDateTime__c": "2023-01-30T14:00:00Z", "Pickup_ScheduledEndDateTime__c": "2023-01-17T21:00:00Z", "Pickup_ScheduledStartDateTime__c": "2023-01-17T13:00:00Z", "Weight__c": 30250, "dest_city__c": "WARMINSTER", "dest_state__c": "PA", "dest_zip__c": "18974", "max_pay__c": 850, "orig_zip__c": "23320", "origin_city__c": "CHESAPEAKE", "origin_state__c": "VA" }, { "#odata.etag": "", "ItemInternalId": "3eac0b25-bde8-4185-89c0-0b15827d13ff", "Delivery_ScheduledEndDateTime__c": "2023-01-20T13:30:00Z", "Delivery_ScheduledStartDateTime__c": "2023-01-20T13:30:00Z", "Pickup_ScheduledEndDateTime__c": "2023-01-16T22:00:00Z", "Pickup_ScheduledStartDateTime__c": "2023-01-16T14:00:00Z", "Weight__c": 38845, "dest_city__c": "MILWAUKIE", "dest_state__c": "OR", "dest_zip__c": "97222", "max_pay__c": 6316.132222873688, "orig_zip__c": "78045", "origin_city__c": "LAREDO", "origin_state__c": "TX" }, { "#odata.etag": "", "ItemInternalId": "e6f249a6-dd8f-4e4f-8de7-d1e37d611896", "Delivery_ScheduledEndDateTime__c": "2023-01-18T18:00:00Z", "Delivery_ScheduledStartDateTime__c": "2023-01-18T14:00:00Z", "Pickup_ScheduledEndDateTime__c": "2023-01-17T21:00:00Z", "Pickup_ScheduledStartDateTime__c": "2023-01-17T13:00:00Z", "Weight__c": 30250, "dest_city__c": "WARMINSTER", "dest_state__c": "PA", "dest_zip__c": "18974", "max_pay__c": 900, "orig_zip__c": "23320", "origin_city__c": "CHESAPEAKE", "origin_state__c": "VA" }, { "#odata.etag": "", "ItemInternalId": "a2593a84-a224-4e78-bdf0-184d4ad112bd", "Delivery_ScheduledEndDateTime__c": "2023-01-23T13:30:00Z", "Delivery_ScheduledStartDateTime__c": "2023-01-23T13:30:00Z", "Pickup_ScheduledEndDateTime__c": "2023-01-18T17:00:00Z", "Pickup_ScheduledStartDateTime__c": "2023-01-18T17:00:00Z", "Weight__c": 42640, "dest_city__c": "MILWAUKIE", "dest_state__c": "OR", "dest_zip__c": "97222", "max_pay__c": 5700, "orig_zip__c": "08837", "origin_city__c": "EDISON", "origin_state__c": "NJ" }, { "#odata.etag": "", "ItemInternalId": "be8ba5c3-ea31-4da5-9369-17055c3776c2", "Delivery_ScheduledEndDateTime__c": "2023-01-18T16:00:00Z", "Delivery_ScheduledStartDateTime__c": "2023-01-18T16:00:00Z", "Pickup_ScheduledEndDateTime__c": "2023-01-16T18:00:00Z", "Pickup_ScheduledStartDateTime__c": "2023-01-16T18:00:00Z", "Weight__c": 24624, "dest_city__c": "FOREST PARK", "dest_state__c": "GA", "dest_zip__c": "30297", "max_pay__c": 2700, "orig_zip__c": "78045", "origin_city__c": "LAREDO", "origin_state__c": "TX" }, { "#odata.etag": "", "ItemInternalId": "05b6dfb9-f502-4de5-b6b4-827c18706c33", "Delivery_ScheduledEndDateTime__c": "2023-01-13T16:00:00Z", "Delivery_ScheduledStartDateTime__c": "2023-01-13T16:00:00Z", "Pickup_ScheduledEndDateTime__c": "2023-01-12T19:00:00Z", "Pickup_ScheduledStartDateTime__c": "2023-01-12T19:00:00Z", "Weight__c": 35998, "dest_city__c": "PHILADELPHIA", "dest_state__c": "PA", "dest_zip__c": "19154", "max_pay__c": 655.6680024414063, "orig_zip__c": "21075", "origin_city__c": "ELKRIDGE", "origin_state__c": "MD" } ] } }
I can see that the variable that you are trying to pass is actually max_pay__c but you are using max_pay_c for your expression. After making that change from my end, this was working fine. Below is the expression I'm using. mul(items('For_each')?['max_pay__c'],0.95) RESULTS:
You need first find the datatype for max_pay_c. Let's suppose it is a nullable integer, you need to add some extra logic to handle that, like: mul(0.95,if(equals(item()?['max_pay_c'], null),0,item()?['max_pay_c'])) either that or something to skip the calculation when null
Uncaught Error: TypeError: null: type 'JSNull' is not a subtype of type 'List<dynamic>'
I'm looking for a way to copy the values in the category_name field to a list without using the add operator. The idea behind not using the add operator is to prevent the existing data from remaining in the list. For example, if in a newer JSON data set, the values in category_name are [xyz, food] & [efg, food], then I intend to print [xyz, efg] instead of [Veg, Veg, NonVeg, XYZ, efg]. Please note that the JSON data currently assigned to duplicates is meant to be dynamic which is why it is important for me to find a solution in which I can only assign the values in category_name from the current JSON data set which is meant to change with API calls. void main() { List<dynamic> list = []; Map<String, dynamic> duplicates = { "status": "success", "data": [ { "product_id": 17, "category_name": [ "Veg", "Dinner" ], "restaurant_name": "Mocambo", "product_name": "Panner Makhani", "product_description": "Mouth Smacking Creamy Indian Gravy.", "product_image": "/assets/product/WOw4Rc03-02-08.jpg", "product_selling_price": "240", "product_status": "active", "product_quantity": "50", "product_rating": "", "product_rating_count": "", "product_sell_count": "0" }, { "product_id": 16, "category_name": [ "Veg", "Dinner" ], "restaurant_name": "Mocambo", "product_name": "Panner Makhani", "product_description": "Mouth Smacking Creamy Indian Gravy.", "product_image": "/assets/product/WOw4Rc03-02-08.jpg", "product_selling_price": "240", "product_status": "active", "product_quantity": "50", "product_rating": "", "product_rating_count": "", "product_sell_count": "0" }, { "product_id": 15, "category_name": [ "NonVeg", "Snacks" ], "restaurant_name": "Mocambo", "product_name": "Cheese Steak Burger", "product_description": "Tasty steak burger oozing with the goodness of creamy cheese", "product_image": "/assets/product/SBuZnx02-54-20.jpg", "product_selling_price": "150", "product_status": "active", "product_quantity": "20", "product_rating": "", "product_rating_count": "", "product_sell_count": "0" } ] }; list = duplicates['data'].forEach((value) => value["category_name"][0]); print(list); } I tried doing list = duplicates['data'].forEach((value) => value["category_name"][0]); thinking that everytime the JSON data in duplicates changes, the previous values will get overwritten with new ones. But it doesn't really work that way because of the above error. Any help will be appreciated.
How to use count and where function in MongoDB?
Need some help here..have been stuck for awhile. List all Name, Company Name of clients who have applied more than 2 loans which has a yearly repayment plan. I should get 3 outputs: John Tan, Happy Food Industry Pte Ltd Mary Lee, Nice Man Advertising Pte Ltd Yuyu Lee, NAGM Tuition Centre My dataset: [ { "name": "John Tan", "contact_number": [ "81726351", "92019283", "90192837" ], "company_name": "Happy Food Industry Pte Ltd", "company_registration_number": 950001819, "type_of_ownership": "owner", "last_roll_call": "16-06-21", "follow_up_notes": "Do not require any loan at this moment", "need_to_follow_up": "Yes", "plan_next_call": "01-12-21", "financial_year_ended": "30-06-21", "profit_and_lost_as_on_last_closing": 8000, "cumulative_profit_and_lost_as_on_last_closing": 50000, "loan_applied": [ "Purchase of delivery lorry", "Renovation of tuition centre" ], "commission_date": "01-12-19", "loan_duration_in_mths": 24, "interest_rate": 3, "repayment_plan": "yearly", "loan_amount": 138058298, "status": "Requesting for delay payments", "other_notes": null }, { "name": "Mary Lee", "contact_number": [ "95213355" ], "company_name": "Nice Man Advertising Pte Ltd", "company_registration_number": 960087657, "type_of_ownership": "Partner with 50% holding", "last_roll_call": "15-06-21", "follow_up_notes": "Do not require any loan at this moment", "need_to_follow_up": "Yes", "plan_next_call": "Dec 21", "financial_year_ended": "30-01-21", "profit_and_lost_as_on_last_closing": 9000, "cumulative_profit_and_lost_as_on_last_closing": 40000, "loan_applied": [ "Purchase of crane", "Purchase of machinery from USA" ], "commission_date": "01-11-19", "loan_duration_in_mths": 23, "interest_rate": 4, "repayment_plan": "yearly", "loan_amount": 1237162, "status": "Healthy", "other_notes": null }, { "name": "Yuyu Lee", "contact_number": [ "928371623" ], "company_name": "NAGM Tuition Centre", "type_of_ownership": "Partner with 20% holding", "follow_up_notes": "Do not require any loan at this moment", "need_to_follow_up": "Yes", "plan_next_call": "12-12-21", "financial_year_ended": "30-01-21", "profit_and_lost_as_on_last_closing": 1000000, "cumulative_profit_and_lost_as_on_last_closing": 3002000, "loan_applied": [ "Purchase of raw material from China", "Renovation of shopping mall" ], "commission_date": "01-11-19", "loan_duration_in_mths": 11, "interest_rate": 4, "repayment_plan": "yearly", "loan_amount": 918272, "status": "Completed", "other_notes": null }, { "name": "Joseph Lee", "contact_number": [ "918273615", "0192837176", "1827361923" ], "company_name": "Akaka Tuition Centre", "company_registration_number": 929381782, "type_of_ownership": "Director", "last_roll_call": "15-11-21", "follow_up_notes": "Do not require any loan at this moment", "need_to_follow_up": "No", "plan_next_call": null, "financial_year_ended": "30-01-21", "profit_and_lost_as_on_last_closing": 999999, "cumulative_profit_and_lost_as_on_last_closing": 9000, "loan_applied": "Purchase of delivery lorry", "commission_date": "01-11-19", "loan_duration_in_mths": 11, "interest_rate": 4, "repayment_plan": "monthly", "loan_amount": 918272, "status": "Completed", "other_notes": null }, { "name": "Tan Meh Meh", "contact_number": [ "92837162", "9189278371" ], "company_name": "Target Pte Ltd", "company_registration_number": 293891823, "type_of_ownership": "Director", "last_roll_call": "15-12-21", "follow_up_notes": "Do not require any loan at this moment", "need_to_follow_up": "Yes", "plan_next_call": "09-12-21", "financial_year_ended": "30-01-21", "profit_and_lost_as_on_last_closing": 12500000, "cumulative_profit_and_lost_as_on_last_closing": 1500000, "loan_applied": "Purchase of delivery lorry", "commission_date": "01-11-19", "loan_duration_in_mths": 55, "interest_rate": 4, "repayment_plan": "monthly", "loan_amount": 918272, "status": "Completed", "other_notes": null }, { "name": "Teo Bee Bee", "contact_number": [ "92039189278", "192838182", "192837172" ], "company_name": "Hello Kitty Pte Ltd", "company_registration_number": 102039192, "type_of_ownership": "Owner", "last_roll_call": "13-11-21", "follow_up_notes": "Do not require any loan at this moment", "need_to_follow_up": "Yes", "plan_next_call": "09-01-21", "financial_year_ended": "30-01-21", "profit_and_lost_as_on_last_closing": 6000, "cumulative_profit_and_lost_as_on_last_closing": 24000000, "loan_applied": "Purchase of delivery lorry", "commission_date": "01-11-19", "loan_duration_in_mths": 33, "interest_rate": 4, "repayment_plan": "monthly", "loan_amount": 2312333, "status": "Requesting for delay payments", "other_notes": null } ]
The following query will get you what is needed. db.collection.find( { "loan_applied.1": { "$exists": true }, "repayment_plan": "yearly" } , {"name":1, "company_name": 1} ); Explanation: Since loan_applied is an array field, we can use the dot notation to see if any element exist after the index 1, which means more than 1 element. We add one more filter for repayment_plan. In the second part of the query, we use projection to return back only name and company_name.
How to test the Google Schemas
I am trying to implement the ParcelDelivery feature for my webshop as shown here: https://developers.google.com/gmail/markup/reference/parcel-delivery The markup i use validates using this tool: https://www.google.com/webmasters/markup-tester/ On the help pages it shows that you can test this markup by sending an email from yourself, to yourself. So i am sending myself an email using the GMail web interface, but no matter what i use for the formatting (plain text or html) the "package delivery status" does not show up in my inbox. Instead, when i click to open the email; the entire code below is shown as the email, just if GMail does not pick it up. p.s. is this schema also supported in the NOW cards? does anybody know? Am i doing something wrong? This is my source used: <html> <body> <script type="application/ld+json"> { "#context": "http://schema.org", "#type": "ParcelDelivery", "deliveryAddress": { "#type": "PostalAddress", "name": "John Frank", "streetAddress": "24 Willie Mays Plaza", "addressLocality": "San Francisco", "addressRegion": "CA", "addressCountry": "US", "postalCode": "94107" }, "originAddress": { "#type": "PostalAddress", "name": "John Frank", "streetAddress": "25 Willie Mays Plaza", "addressLocality": "San Francisco", "addressRegion": "CA", "addressCountry": "US", "postalCode": "94107" }, "expectedArrivalFrom": "2013-03-10T12:00:00-08:00", "expectedArrivalUntil": "2013-03-12T12:00:00-08:00", "carrier": { "#type": "Organization", "name": "FedEx", "url": "http://fedex.com/" }, "itemShipped": { "#type": "Product", "name": "iPod Mini", "url": "http://apple.com/ipad32gb", "image": "http://apple.com/images/ipad32gb.jpg", "sku": "B00DR0PDNE", "description": "iPod Mini 32Gb White", "brand": { "#type": "Brand", "name": "Apple" }, "color": "white" }, "trackingNumber": "3453291231", "trackingUrl": "http://fedex.com/track/3453291231", "hasDeliveryMethod": "http://schema.org/ParcelService", "partOfOrder": { "#type": "Order", "orderNumber": "176057", "merchant": { "#type": "Organization", "name": "Bob Dole", "sameAs": "http://www.freebase.com/m/0fhkx" }, "orderStatus": "http://schema.org/OrderInTransit" } } </script> <p> Dear John, thanks for booking your Google I/O ticket with us. </p> <p> BOOKING DETAILS<br/> Reservation number: IO12345<br/> Order for: John Smith<br/> Event: Google I/O 2013<br/> Start time: May 15th 2013 8:00am PST<br/> Venue: Moscone Center, 800 Howard St., San Francisco, CA 94103<br/> </p> </body> </html>
How to get the user's country calling code in iOS?
I am developing an iOS app in which the user enters their mobile number. How do I get their country calling code? For example, if a user is in India, then +91 should be prefixed automatically. Is there an option that adds country codes automatically?
Import Statement : #import<CoreTelephony/CTCarrier.h> #import <CoreTelephony/CTTelephonyNetworkInfo.h> you can get country code for the current Carrier using CoreTelephony framework: CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new]; CTCarrier *carrier = network_Info.subscriberCellularProvider; NSLog(#"country code is: %#", carrier.mobileCountryCode); //will return the actual country code NSLog(#"ISO country code is: %#", carrier.isoCountryCode); Apple Docs
with the use of NSLocale you can get the country name, code etc. Take a look at below code it will help you to do so. NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; // get country code, e.g. ES (Spain), FR (France), etc. for a countries dialing code you can visit this reference code.
Use this simple function func getCountryCallingCode(countryRegionCode:String)->String{ let prefixCodes = ["AF": "93", "AE": "971", "AL": "355", "AN": "599", "AS":"1", "AD": "376", "AO": "244", "AI": "1", "AG":"1", "AR": "54","AM": "374", "AW": "297", "AU":"61", "AT": "43","AZ": "994", "BS": "1", "BH":"973", "BF": "226","BI": "257", "BD": "880", "BB": "1", "BY": "375", "BE":"32","BZ": "501", "BJ": "229", "BM": "1", "BT":"975", "BA": "387", "BW": "267", "BR": "55", "BG": "359", "BO": "591", "BL": "590", "BN": "673", "CC": "61", "CD":"243","CI": "225", "KH":"855", "CM": "237", "CA": "1", "CV": "238", "KY":"345", "CF":"236", "CH": "41", "CL": "56", "CN":"86","CX": "61", "CO": "57", "KM": "269", "CG":"242", "CK": "682", "CR": "506", "CU":"53", "CY":"537","CZ": "420", "DE": "49", "DK": "45", "DJ":"253", "DM": "1", "DO": "1", "DZ": "213", "EC": "593", "EG":"20", "ER": "291", "EE":"372","ES": "34", "ET": "251", "FM": "691", "FK": "500", "FO": "298", "FJ": "679", "FI":"358", "FR": "33", "GB":"44", "GF": "594", "GA":"241", "GS": "500", "GM":"220", "GE":"995","GH":"233", "GI": "350", "GQ": "240", "GR": "30", "GG": "44", "GL": "299", "GD":"1", "GP": "590", "GU": "1", "GT": "502", "GN":"224","GW": "245", "GY": "595", "HT": "509", "HR": "385", "HN":"504", "HU": "36", "HK": "852", "IR": "98", "IM": "44", "IL": "972", "IO":"246", "IS": "354", "IN": "91", "ID":"62", "IQ":"964", "IE": "353","IT":"39", "JM":"1", "JP": "81", "JO": "962", "JE":"44", "KP": "850", "KR": "82","KZ":"77", "KE": "254", "KI": "686", "KW": "965", "KG":"996","KN":"1", "LC": "1", "LV": "371", "LB": "961", "LK":"94", "LS": "266", "LR":"231", "LI": "423", "LT": "370", "LU": "352", "LA": "856", "LY":"218", "MO": "853", "MK": "389", "MG":"261", "MW": "265", "MY": "60","MV": "960", "ML":"223", "MT": "356", "MH": "692", "MQ": "596", "MR":"222", "MU": "230", "MX": "52","MC": "377", "MN": "976", "ME": "382", "MP": "1", "MS": "1", "MA":"212", "MM": "95", "MF": "590", "MD":"373", "MZ": "258", "NA":"264", "NR":"674", "NP":"977", "NL": "31","NC": "687", "NZ":"64", "NI": "505", "NE": "227", "NG": "234", "NU":"683", "NF": "672", "NO": "47","OM": "968", "PK": "92", "PM": "508", "PW": "680", "PF": "689", "PA": "507", "PG":"675", "PY": "595", "PE": "51", "PH": "63", "PL":"48", "PN": "872","PT": "351", "PR": "1","PS": "970", "QA": "974", "RO":"40", "RE":"262", "RS": "381", "RU": "7", "RW": "250", "SM": "378", "SA":"966", "SN": "221", "SC": "248", "SL":"232","SG": "65", "SK": "421", "SI": "386", "SB":"677", "SH": "290", "SD": "249", "SR": "597","SZ": "268", "SE":"46", "SV": "503", "ST": "239","SO": "252", "SJ": "47", "SY":"963", "TW": "886", "TZ": "255", "TL": "670", "TD": "235", "TJ": "992", "TH": "66", "TG":"228", "TK": "690", "TO": "676", "TT": "1", "TN":"216","TR": "90", "TM": "993", "TC": "1", "TV":"688", "UG": "256", "UA": "380", "US": "1", "UY": "598","UZ": "998", "VA":"379", "VE":"58", "VN": "84", "VG": "1", "VI": "1","VC":"1", "VU":"678", "WS": "685", "WF": "681", "YE": "967", "YT": "262","ZA": "27" , "ZM": "260", "ZW":"263"] let countryDialingCode = prefixCodes[countryRegionCode] return countryDialingCode! } And call as let currentLocale = NSLocale.currentLocale() let countryCode = currentLocale.objectForKey(NSLocaleCountryCode) as! String//get the set country name, code of your iphone print("country code is \(countryCode)") print(getCountryCallingCode(countryCode)) //change country region Settings>>General>>Language&Region>>Region
Swift let networkInfo = CTTelephonyNetworkInfo() if let carrier = networkInfo.subscriberCellularProvider { print("country code is: " + carrier.mobileCountryCode!); //will return the actual country code print("ISO country code is: " + carrier.isoCountryCode!); }
Swift 5 I combine answer from Oded and LC into a function. func getCountryCode() -> String { guard let carrier = CTTelephonyNetworkInfo().subscriberCellularProvider, let countryCode = carrier.isoCountryCode else { return "" } let prefixCodes = ["AF": "93", "AE": "971", "AL": "355", "AN": "599", "AS":"1", "AD": "376", "AO": "244", "AI": "1", "AG":"1", "AR": "54","AM": "374", "AW": "297", "AU":"61", "AT": "43","AZ": "994", "BS": "1", "BH":"973", "BF": "226","BI": "257", "BD": "880", "BB": "1", "BY": "375", "BE":"32","BZ": "501", "BJ": "229", "BM": "1", "BT":"975", "BA": "387", "BW": "267", "BR": "55", "BG": "359", "BO": "591", "BL": "590", "BN": "673", "CC": "61", "CD":"243","CI": "225", "KH":"855", "CM": "237", "CA": "1", "CV": "238", "KY":"345", "CF":"236", "CH": "41", "CL": "56", "CN":"86","CX": "61", "CO": "57", "KM": "269", "CG":"242", "CK": "682", "CR": "506", "CU":"53", "CY":"537","CZ": "420", "DE": "49", "DK": "45", "DJ":"253", "DM": "1", "DO": "1", "DZ": "213", "EC": "593", "EG":"20", "ER": "291", "EE":"372","ES": "34", "ET": "251", "FM": "691", "FK": "500", "FO": "298", "FJ": "679", "FI":"358", "FR": "33", "GB":"44", "GF": "594", "GA":"241", "GS": "500", "GM":"220", "GE":"995","GH":"233", "GI": "350", "GQ": "240", "GR": "30", "GG": "44", "GL": "299", "GD":"1", "GP": "590", "GU": "1", "GT": "502", "GN":"224","GW": "245", "GY": "595", "HT": "509", "HR": "385", "HN":"504", "HU": "36", "HK": "852", "IR": "98", "IM": "44", "IL": "972", "IO":"246", "IS": "354", "IN": "91", "ID":"62", "IQ":"964", "IE": "353","IT":"39", "JM":"1", "JP": "81", "JO": "962", "JE":"44", "KP": "850", "KR": "82","KZ":"77", "KE": "254", "KI": "686", "KW": "965", "KG":"996","KN":"1", "LC": "1", "LV": "371", "LB": "961", "LK":"94", "LS": "266", "LR":"231", "LI": "423", "LT": "370", "LU": "352", "LA": "856", "LY":"218", "MO": "853", "MK": "389", "MG":"261", "MW": "265", "MY": "60","MV": "960", "ML":"223", "MT": "356", "MH": "692", "MQ": "596", "MR":"222", "MU": "230", "MX": "52","MC": "377", "MN": "976", "ME": "382", "MP": "1", "MS": "1", "MA":"212", "MM": "95", "MF": "590", "MD":"373", "MZ": "258", "NA":"264", "NR":"674", "NP":"977", "NL": "31","NC": "687", "NZ":"64", "NI": "505", "NE": "227", "NG": "234", "NU":"683", "NF": "672", "NO": "47","OM": "968", "PK": "92", "PM": "508", "PW": "680", "PF": "689", "PA": "507", "PG":"675", "PY": "595", "PE": "51", "PH": "63", "PL":"48", "PN": "872","PT": "351", "PR": "1","PS": "970", "QA": "974", "RO":"40", "RE":"262", "RS": "381", "RU": "7", "RW": "250", "SM": "378", "SA":"966", "SN": "221", "SC": "248", "SL":"232","SG": "65", "SK": "421", "SI": "386", "SB":"677", "SH": "290", "SD": "249", "SR": "597","SZ": "268", "SE":"46", "SV": "503", "ST": "239","SO": "252", "SJ": "47", "SY":"963", "TW": "886", "TZ": "255", "TL": "670", "TD": "235", "TJ": "992", "TH": "66", "TG":"228", "TK": "690", "TO": "676", "TT": "1", "TN":"216","TR": "90", "TM": "993", "TC": "1", "TV":"688", "UG": "256", "UA": "380", "US": "1", "UY": "598","UZ": "998", "VA":"379", "VE":"58", "VN": "84", "VG": "1", "VI": "1","VC":"1", "VU":"678", "WS": "685", "WF": "681", "YE": "967", "YT": "262","ZA": "27" , "ZM": "260", "ZW":"263"] let countryDialingCode = prefixCodes[countryCode.uppercased()] ?? "" return countryDialingCode } Make sure to import CoreTelephony at the top import CoreTelephony
I think you need to use NSLocale for using Country code of the user. You can follow this link to understand use of NSLocale class reference. Also study this link for ISOCountryCode property. Hope this may help you.
I came up with the following code, based on previous answers: Swift #if canImport(CoreTelephony) import CoreTelephony #endif static func getRegionCodeFromSim() -> String? { #if canImport(CoreTelephony) let networkInfos = CTTelephonyNetworkInfo() if #available(iOS 12, *) { let carrier = networkInfos.serviceSubscriberCellularProviders? .map { $0.1 } .first { $0.isoCountryCode != nil } return carrier?.isoCountryCode } return networkInfos.subscriberCellularProvider?.isoCountryCode #else return nil #endif } static func getRegionCode() -> String? { guard let regionCodeFromSim = Self.getRegionCodeFromSim() else { return NSLocale.current.regionCode } return regionCodeFromSim } static func getCountryCode() -> String? { guard let regionCode = Self.getRegionCode() else { return nil } let prefixCodes = ["AF": "93", "AE": "971", "AL": "355", "AN": "599", "AS":"1", "AD": "376", "AO": "244", "AI": "1", "AG":"1", "AR": "54","AM": "374", "AW": "297", "AU":"61", "AT": "43","AZ": "994", "BS": "1", "BH":"973", "BF": "226","BI": "257", "BD": "880", "BB": "1", "BY": "375", "BE":"32","BZ": "501", "BJ": "229", "BM": "1", "BT":"975", "BA": "387", "BW": "267", "BR": "55", "BG": "359", "BO": "591", "BL": "590", "BN": "673", "CC": "61", "CD":"243","CI": "225", "KH":"855", "CM": "237", "CA": "1", "CV": "238", "KY":"345", "CF":"236", "CH": "41", "CL": "56", "CN":"86","CX": "61", "CO": "57", "KM": "269", "CG":"242", "CK": "682", "CR": "506", "CU":"53", "CY":"537","CZ": "420", "DE": "49", "DK": "45", "DJ":"253", "DM": "1", "DO": "1", "DZ": "213", "EC": "593", "EG":"20", "ER": "291", "EE":"372","ES": "34", "ET": "251", "FM": "691", "FK": "500", "FO": "298", "FJ": "679", "FI":"358", "FR": "33", "GB":"44", "GF": "594", "GA":"241", "GS": "500", "GM":"220", "GE":"995","GH":"233", "GI": "350", "GQ": "240", "GR": "30", "GG": "44", "GL": "299", "GD":"1", "GP": "590", "GU": "1", "GT": "502", "GN":"224","GW": "245", "GY": "595", "HT": "509", "HR": "385", "HN":"504", "HU": "36", "HK": "852", "IR": "98", "IM": "44", "IL": "972", "IO":"246", "IS": "354", "IN": "91", "ID":"62", "IQ":"964", "IE": "353","IT":"39", "JM":"1", "JP": "81", "JO": "962", "JE":"44", "KP": "850", "KR": "82","KZ":"77", "KE": "254", "KI": "686", "KW": "965", "KG":"996","KN":"1", "LC": "1", "LV": "371", "LB": "961", "LK":"94", "LS": "266", "LR":"231", "LI": "423", "LT": "370", "LU": "352", "LA": "856", "LY":"218", "MO": "853", "MK": "389", "MG":"261", "MW": "265", "MY": "60","MV": "960", "ML":"223", "MT": "356", "MH": "692", "MQ": "596", "MR":"222", "MU": "230", "MX": "52","MC": "377", "MN": "976", "ME": "382", "MP": "1", "MS": "1", "MA":"212", "MM": "95", "MF": "590", "MD":"373", "MZ": "258", "NA":"264", "NR":"674", "NP":"977", "NL": "31","NC": "687", "NZ":"64", "NI": "505", "NE": "227", "NG": "234", "NU":"683", "NF": "672", "NO": "47","OM": "968", "PK": "92", "PM": "508", "PW": "680", "PF": "689", "PA": "507", "PG":"675", "PY": "595", "PE": "51", "PH": "63", "PL":"48", "PN": "872","PT": "351", "PR": "1","PS": "970", "QA": "974", "RO":"40", "RE":"262", "RS": "381", "RU": "7", "RW": "250", "SM": "378", "SA":"966", "SN": "221", "SC": "248", "SL":"232","SG": "65", "SK": "421", "SI": "386", "SB":"677", "SH": "290", "SD": "249", "SR": "597","SZ": "268", "SE":"46", "SV": "503", "ST": "239","SO": "252", "SJ": "47", "SY":"963", "TW": "886", "TZ": "255", "TL": "670", "TD": "235", "TJ": "992", "TH": "66", "TG":"228", "TK": "690", "TO": "676", "TT": "1", "TN":"216","TR": "90", "TM": "993", "TC": "1", "TV":"688", "UG": "256", "UA": "380", "US": "1", "UY": "598","UZ": "998", "VA":"379", "VE":"58", "VN": "84", "VG": "1", "VI": "1","VC":"1", "VU":"678", "WS": "685", "WF": "681", "YE": "967", "YT": "262","ZA": "27" , "ZM": "260", "ZW":"263"] return prefixCodes[regionCode.uppercased()] } It tries to fetch the country code from the SIM cards (with multi-sim & non-sim devices support), if available, and fallbacks to the device's locale otherwise. The prefixCodes could be loaded from a PLIST or JSON to help with readability.
If you want to prefixed calling country code automatically then you need to get user's country code pragmatically and Drag & drop src Folder in your code Its looks like this: if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String { print(countryCode) let strCode = Countries.countryFromCountryCode(countryCode: countryCode) btnPhoneCode.setTitle("+\(strCode.phoneExtension)", for: .normal) } It works for me, Hope will help you too. :)
NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; // get country code, e.g. ES (Spain), FR (France), etc. NSLog(#"country code is:%#",countryCode); NSString*lower=[countryCode lowercaseString]; NSString *path = [[NSBundle mainBundle] pathForResource:#"DiallingCodes" ofType:#"plist"]; NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; NSMutableDictionary *_dictCountry=[[NSMutableDictionary alloc]init]; NSMutableArray *_CodeArray=[[NSMutableArray alloc]init]; [_CodeArray addObject:dict]; _dictCountry = [_CodeArray objectAtIndex:0]; NSString*Country_code=[NSString stringWithFormat:#"+%#",[_dictCountry objectForKey:lower]]; contactTextField.text=Country_code;
You can request to this url. For get CountryCode or ip, region_name, city, long, lat NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:#"http://freegeoip.net/json/"]]; __block NSDictionary *json; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; NSLog(#"Countrycode: %#", json[#"country_code"]); }];
Here the Objective C code #import<CoreTelephony/CTCarrier.h> #import <CoreTelephony/CTTelephonyNetworkInfo.h> - (void)viewDidLoad{ CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new]; CTCarrier *carrier = network_Info.subscriberCellularProvider; NSLog(#"country code is: %#", carrier.mobileCountryCode); NSLog(#"ISO country code is: %#", carrier.mobileNetworkCode); NSLog(#"diling code == %#",[self getCountryCode:carrier.isoCountryCode]); } - (NSString *)getCountryCode:(NSString *)countryISOCode{ NSDictionary * code = #{#"AF": #"93", #"AE": #"971", #"AL": #"355", #"AN": #"599", #"AS":#"1", #"AD": #"376", #"AO": #"244", #"AI": #"1", #"AG":#"1", #"AR": #"54",#"AM": #"374", #"AW": #"297", #"AU":#"61", #"AT": #"43",#"AZ": #"994", #"BS": #"1", #"BH":#"973", #"BF": #"226",#"BI": #"257", #"BD": #"880", #"BB": #"1", #"BY": #"375", #"BE":#"32",#"BZ": #"501", #"BJ": #"229", #"BM": #"1", #"BT":#"975", #"BA": #"387", #"BW": #"267", #"BR": #"55", #"BG": #"359", #"BO": #"591", #"BL": #"590", #"BN": #"673", #"CC": #"61", #"CD":#"243",#"CI": #"225", #"KH":#"855", #"CM": #"237", #"CA": #"1", #"CV": #"238", #"KY":#"345", #"CF":#"236", #"CH": #"41", #"CL": #"56", #"CN":#"86",#"CX": #"61", #"CO": #"57", #"KM": #"269", #"CG":#"242", #"CK": #"682", #"CR": #"506", #"CU":#"53", #"CY":#"537",#"CZ": #"420", #"DE": #"49", #"DK": #"45", #"DJ":#"253", #"DM": #"1", #"DO": #"1", #"DZ": #"213", #"EC": #"593", #"EG":#"20", #"ER": #"291", #"EE":#"372",#"ES": #"34", #"ET": #"251", #"FM": #"691", #"FK": #"500", #"FO": #"298", #"FJ": #"679", #"FI":#"358", #"FR": #"33", #"GB":#"44", #"GF": #"594", #"GA":#"241", #"GS": #"500", #"GM":#"220", #"GE":#"995",#"GH":#"233", #"GI": #"350", #"GQ": #"240", #"GR": #"30", #"GG": #"44", #"GL": #"299", #"GD":#"1", #"GP": #"590", #"GU": #"1", #"GT": #"502", #"GN":#"224",#"GW": #"245", #"GY": #"595", #"HT": #"509", #"HR": #"385", #"HN":#"504", #"HU": #"36", #"HK": #"852", #"IR": #"98", #"IM": #"44", #"IL": #"972", #"IO":#"246", #"IS": #"354", #"IN": #"91", #"ID":#"62", #"IQ":#"964", #"IE": #"353",#"IT":#"39", #"JM":#"1", #"JP": #"81", #"JO": #"962", #"JE":#"44", #"KP": #"850", #"KR": #"82",#"KZ":#"77", #"KE": #"254", #"KI": #"686", #"KW": #"965", #"KG":#"996",#"KN":#"1", #"LC": #"1", #"LV": #"371", #"LB": #"961", #"LK":#"94", #"LS": #"266", #"LR":#"231", #"LI": #"423", #"LT": #"370", #"LU": #"352", #"LA": #"856", #"LY":#"218", #"MO": #"853", #"MK": #"389", #"MG":#"261", #"MW": #"265", #"MY": #"60",#"MV": #"960", #"ML":#"223", #"MT": #"356", #"MH": #"692", #"MQ": #"596", #"MR":#"222", #"MU": #"230", #"MX": #"52",#"MC": #"377", #"MN": #"976", #"ME": #"382", #"MP": #"1", #"MS": #"1", #"MA":#"212", #"MM": #"95", #"MF": #"590", #"MD":#"373", #"MZ": #"258", #"NA":#"264", #"NR":#"674", #"NP":#"977", #"NL": #"31",#"NC": #"687", #"NZ":#"64", #"NI": #"505", #"NE": #"227", #"NG": #"234", #"NU":#"683", #"NF": #"672", #"NO": #"47",#"OM": #"968", #"PK": #"92", #"PM": #"508", #"PW": #"680", #"PF": #"689", #"PA": #"507", #"PG":#"675", #"PY": #"595", #"PE": #"51", #"PH": #"63", #"PL":#"48", #"PN": #"872",#"PT": #"351", #"PR": #"1",#"PS": #"970", #"QA": #"974", #"RO":#"40", #"RE":#"262", #"RS": #"381", #"RU": #"7", #"RW": #"250", #"SM": #"378", #"SA":#"966", #"SN": #"221", #"SC": #"248", #"SL":#"232",#"SG": #"65", #"SK": #"421", #"SI": #"386", #"SB":#"677", #"SH": #"290", #"SD": #"249", #"SR": #"597",#"SZ": #"268", #"SE":#"46", #"SV": #"503", #"ST": #"239",#"SO": #"252", #"SJ": #"47", #"SY":#"963", #"TW": #"886", #"TZ": #"255", #"TL": #"670", #"TD": #"235", #"TJ": #"992", #"TH": #"66", #"TG":#"228", #"TK": #"690", #"TO": #"676", #"TT": #"1", #"TN":#"216",#"TR": #"90", #"TM": #"993", #"TC": #"1", #"TV":#"688", #"UG": #"256", #"UA": #"380", #"US": #"1", #"UY": #"598",#"UZ": #"998", #"VA":#"379", #"VE":#"58", #"VN": #"84", #"VG": #"1", #"VI": #"1",#"VC":#"1", #"VU":#"678", #"WS": #"685", #"WF": #"681", #"YE": #"967", #"YT": #"262",#"ZA": #"27" , #"ZM": #"260", #"ZW":#"263"}; return [NSString stringWithFormat:#"+%#", [code objectForKey:[countryISOCode uppercaseString]]]; }
Swift 5 Support and using optionals here is my solution: static func GetCountryCallingCode(countryRegionCode:String) -> String? { let prefixCodes = ["AF": "93", "AE": "971", "AL": "355", "AN": "599", "AS":"1", "AD": "376", "AO": "244", "AI": "1", "AG":"1", "AR": "54","AM": "374", "AW": "297", "AU":"61", "AT": "43","AZ": "994", "BS": "1", "BH":"973", "BF": "226","BI": "257", "BD": "880", "BB": "1", "BY": "375", "BE":"32","BZ": "501", "BJ": "229", "BM": "1", "BT":"975", "BA": "387", "BW": "267", "BR": "55", "BG": "359", "BO": "591", "BL": "590", "BN": "673", "CC": "61", "CD":"243","CI": "225", "KH":"855", "CM": "237", "CA": "1", "CV": "238", "KY":"345", "CF":"236", "CH": "41", "CL": "56", "CN":"86","CX": "61", "CO": "57", "KM": "269", "CG":"242", "CK": "682", "CR": "506", "CU":"53", "CY":"537","CZ": "420", "DE": "49", "DK": "45", "DJ":"253", "DM": "1", "DO": "1", "DZ": "213", "EC": "593", "EG":"20", "ER": "291", "EE":"372","ES": "34", "ET": "251", "FM": "691", "FK": "500", "FO": "298", "FJ": "679", "FI":"358", "FR": "33", "GB":"44", "GF": "594", "GA":"241", "GS": "500", "GM":"220", "GE":"995","GH":"233", "GI": "350", "GQ": "240", "GR": "30", "GG": "44", "GL": "299", "GD":"1", "GP": "590", "GU": "1", "GT": "502", "GN":"224","GW": "245", "GY": "595", "HT": "509", "HR": "385", "HN":"504", "HU": "36", "HK": "852", "IR": "98", "IM": "44", "IL": "972", "IO":"246", "IS": "354", "IN": "91", "ID":"62", "IQ":"964", "IE": "353","IT":"39", "JM":"1", "JP": "81", "JO": "962", "JE":"44", "KP": "850", "KR": "82","KZ":"77", "KE": "254", "KI": "686", "KW": "965", "KG":"996","KN":"1", "LC": "1", "LV": "371", "LB": "961", "LK":"94", "LS": "266", "LR":"231", "LI": "423", "LT": "370", "LU": "352", "LA": "856", "LY":"218", "MO": "853", "MK": "389", "MG":"261", "MW": "265", "MY": "60","MV": "960", "ML":"223", "MT": "356", "MH": "692", "MQ": "596", "MR":"222", "MU": "230", "MX": "52","MC": "377", "MN": "976", "ME": "382", "MP": "1", "MS": "1", "MA":"212", "MM": "95", "MF": "590", "MD":"373", "MZ": "258", "NA":"264", "NR":"674", "NP":"977", "NL": "31","NC": "687", "NZ":"64", "NI": "505", "NE": "227", "NG": "234", "NU":"683", "NF": "672", "NO": "47","OM": "968", "PK": "92", "PM": "508", "PW": "680", "PF": "689", "PA": "507", "PG":"675", "PY": "595", "PE": "51", "PH": "63", "PL":"48", "PN": "872","PT": "351", "PR": "1","PS": "970", "QA": "974", "RO":"40", "RE":"262", "RS": "381", "RU": "7", "RW": "250", "SM": "378", "SA":"966", "SN": "221", "SC": "248", "SL":"232","SG": "65", "SK": "421", "SI": "386", "SB":"677", "SH": "290", "SD": "249", "SR": "597","SZ": "268", "SE":"46", "SV": "503", "ST": "239","SO": "252", "SJ": "47", "SY":"963", "TW": "886", "TZ": "255", "TL": "670", "TD": "235", "TJ": "992", "TH": "66", "TG":"228", "TK": "690", "TO": "676", "TT": "1", "TN":"216","TR": "90", "TM": "993", "TC": "1", "TV":"688", "UG": "256", "UA": "380", "US": "1", "UY": "598","UZ": "998", "VA":"379", "VE":"58", "VN": "84", "VG": "1", "VI": "1","VC":"1", "VU":"678", "WS": "685", "WF": "681", "YE": "967", "YT": "262","ZA": "27" , "ZM": "260", "ZW":"263"] let countryDialingCode = prefixCodes[countryRegionCode] return countryDialingCode } guard let regionCode = NSLocale.current.regionCode, let callingCode = GetCountryCallingCode(countryRegionCode: regionCode ) else { return } print("Region: \(regionCode) Country calling code is \(callingCode)")
import CoreTelephony /// Method to get the iso calling code /// /// - Returns: String public static func getCallingCodePrefix() -> String { let networkInfo = CTTelephonyNetworkInfo() let phoneNumberKit = PhoneNumberKit() if #available(iOS 12.0, *) { if let carrier = networkInfo.serviceSubscriberCellularProviders?.map({ $0.1 }).first(where: { $0.isoCountryCode != nil }), let isoCode = carrier.isoCountryCode?.uppercased(), let prefixCode = phoneNumberKit.countryCode(for: isoCode) { return "+" + String(prefixCode) } } else { // Fallback on earlier versions if let carrier = networkInfo.subscriberCellularProvider, let isoCode = carrier.isoCountryCode?.uppercased(), let prefixCode = phoneNumberKit.countryCode(for: isoCode) { return "+" + String(prefixCode) } } return "+" }
Use this code to get the user's country in iOS: func countryName(from countryCode: String) -> String { if let name = (Locale.current as NSLocale).displayName(forKey: .countryCode, value: countryCode) { return name } else { return countryCode } } //Locale.current.regionCode this is used for Get user current country region code countryName(from: Locale.current.regionCode ?? "")