ICloud Keychain stores credit card numbers and expiry dates — without storing or autofilling the security code — and passwords and usernames, Wi-Fi passwords, internet accounts and more. Developers can also update their apps to use keychain, if the app is on a device that uses iOS 7.0.3 or later, or OS X Mavericks 10.9 and later. When you access a website, email account, network server, or other password-protected item, you can choose to save the password in your keychain so you don’t have to remember or enter the password each time. Each user on a Mac has a login keychain. The password for your login keychain matches the password you use to log in to your Mac. With Keychain, Apple Mail operates without asking you to supply all of your account passwords. If you only have one or two accounts in Mail, then you can skip this step, but if you have many Mail accounts, transferring Keychain makes using the new Mac easier. Certificaat Thuiswinkel.org verklaart dat haar lid: het Certificaat Thuiswinkel Waarborg mag voeren. Dit betekent dat Zalando.nl als webshop is gecertificeerd door de Stichting Certificering Thuiswinkel Waarborg. On your Mac, run the Keychain Access tool. It can be opened from the Utilities folder or the Other folder on the Launchpad. Select Keychain Access, expand Certificate Assistant, and then select Request a Certificate from a Certificate Authority.
-->Overview
This tutorial shows you how to use Azure Notification Hubs to send push notifications to an iOS application. You create a blank Xamarin.iOS app that receives push notifications by using the Apple Push Notification service (APNs).
When you're finished, you are able to use your notification hub to broadcast push notifications to all the devices running your app. The finished code is available in the NotificationHubs app sample.
In this tutorial, you create/update code to do the following tasks:
- Generate the certificate signing request file
- Register your app for push notifications
- Create a provisioning profile for the app
- Configure your notification hub for iOS push notifications
- Send test push notifications
Prerequisites
Azure subscription. If you don't have an Azure subscription, create a free Azure account before you begin.
Latest version of Xcode
An iOS 10 (or later version) compatible device
Apple Developer Program membership.
Note
Because of configuration requirements for iOS push notifications, you must deploy and test the sample application on a physical iOS device (iPhone or iPad) instead of in the simulator.
Completing this tutorial is a prerequisite for all other Notification Hubs tutorials for Xamarin.iOS apps.
Generate the certificate-signing request file
The Apple Push Notification Service (APNs) uses certificates to authenticate your push notifications. Follow these instructions to create the necessary push certificate to send and receive notifications. For more information on these concepts, see the official Apple Push Notification Service documentation.
Generate the Certificate Signing Request (CSR) file, which Apple uses to generate a signed push certificate.
On your Mac, run the Keychain Access tool. It can be opened from the Utilities folder or the Other folder on the Launchpad.
Select Keychain Access, expand Certificate Assistant, and then select Request a Certificate from a Certificate Authority.
Note
By default, Keychain Access selects the first item in the list. This can be a problem if you're in the Certificates category and Apple Worldwide Developer Relations Certification Authority is not the first item in the list. Make sure you have a non-key item, or the Apple Worldwide Developer Relations Certification Authority key is selected, before generating the CSR (Certificate Signing Request).
Select your User Email Address, enter your Common Name value, make sure that you specify Saved to disk, and then select Continue. Leave CA Email Address blank as it isn't required.
Enter a name for the CSR file in Save As, select the location in Where, and then select Save.
This action saves the CSR file in the selected location. The default location is Desktop. Remember the location chosen for the file.
Next, register your app with Apple, enable push notifications, and upload the exported CSR to create a push certificate.
Register your app for push notifications
To send push notifications to an iOS app, register your application with Apple, and also register for push notifications.
If you haven't already registered your app, browse to the iOS Provisioning Portal at the Apple Developer Center. Sign in to the portal with your Apple ID, and select Identifiers. Then select + to register a new app.
On the Register a New Identifier screen, select the App IDs radio button. Then select Continue.
Update the following three values for your new app, and then select Continue:
Description: Type a descriptive name for your app.
Bundle ID: Enter a Bundle ID of the form Organization Identifier.Product Name as mentioned in the App Distribution Guide. The Organization Identifier and Product Name values must match the organization identifier and product name you use when you create your Xcode project. In the following screenshot, the NotificationHubs value is used as an organization identifier and the GetStarted value is used as the product name. Make sure the Bundle Identifier value matches the value in your Xcode project, so that Xcode uses the correct publishing profile.
Push Notifications: Check the Push Notifications option in the Capabilities section.
This action generates your App ID and requests that you confirm the information. Select Continue, then select Register to confirm the new App ID.
After you select Register, you see the new App ID as a line item in the Certificates, Identifiers & Profiles page.
In the Certificates, Identifiers & Profiles page, under Identifiers, locate the App ID line item that you just created, and select its row to display the Edit your App ID Configuration screen.
Creating a Certificate for Notification Hubs
A certificate is required to enable the notification hub to work with APNS. This can be done in one of two ways:
- Create a .p12 that can be uploaded directly to Notification Hub.
- Create a .p8 that can be used for token-based authentication (the newer approach).
The newer approach has a number of benefits (compared to using certificates) as documented in Token-based (HTTP/2) authentication for APNS. However, steps have been provided for both approaches.
OPTION 1: Creating a .p12 push certificate that can be uploaded directly to Notification Hub
Scroll down to the checked Push Notifications option, and then select Configure to create the certificate.
The Apple Push Notification service SSL Certificates window appears. Select the Create Certificate button under the Development SSL Certificate section.
The Create a new Certificate screen is displayed.
Note
This tutorial uses a development certificate, which your app uses to generate a unique device token. The same process is used when registering a production certificate. Just make sure that you use the same certificate type when sending notifications.
Select Choose File, browse to the location where you saved the CSR file from the first task, and then double-click the certificate name to load it. Then select Continue.
After the portal creates the certificate, select the Download button. Save the certificate, and remember the location to which it's saved.
The certificate is downloaded and saved to your computer in your Downloads folder.
Note
By default, the downloaded development certificate is named aps_development.cer.
Double-click the downloaded push certificate aps_development.cer. This action installs the new certificate in the Keychain, as shown in the following image:
Note
Although the name in your certificate might be different, the name will be prefixed with Apple Development iOS Push Services.
In Keychain Access, right-click the new push certificate that you created in the Certificates category. Select Export, name the file, select the .p12 format, and then select Save.
You can choose to protect the certificate with a password, but this is optional. Click OK if you want to bypass password creation. Make a note of the file name and location of the exported .p12 certificate. They are used to enable authentication with APNs.
Note
Your .p12 file name and location might be different than what is pictured in this tutorial.
OPTION 2: Creating a .p8 certificate that can be used for token-based authentication
Make note of the following details:
- App ID Prefix (this is a Team ID)
- Bundle ID
Back in Certificates, Identifiers & Profiles, click Keys.
Note
If you already have a key configured for APNS, you can re-use the .p8 certificate that you downloaded right after it was created. If so, you can ignore steps 3 through 5.
Click the + button (or the Create a key button) to create a new key.
Provide a suitable Key Name value, then check the Apple Push Notifications service (APNs) option, and then click Continue, followed by Register on the next screen.
Click Download and then move the .p8 file (prefixed with AuthKey_) to a secure local directory, then click Done.
Note
Be sure to keep your .p8 file in a secure place (and save a backup). After downloading your key, it cannot be re-downloaded as the server copy is removed.
On Keys, click on the key that you just created (or an existing key if you have chosen to use that instead).
Make note of the Key ID value.
Open your .p8 certificate in a suitable application of your choice such as Visual Studio Code then make note of the key value. This is the value between -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY----- .
Note
This is the token value that will be used later to configure Notification Hub.
At the end of these steps you should have the following information for use later in Configure your notification hub with APNs information:
- Team ID (see step 1)
- Bundle ID (see step 1)
- Key ID (see step 7)
- Token value i.e. the .p8 key value (see step 8)
Create a provisioning profile for the app
Mac Can't Change Keychain Password
Return to the iOS Provisioning Portal, select Certificates, Identifiers & Profiles, select Profiles from the left menu, and then select + to create a new profile. The Register a New Provisioning Profile screen appears.
Select iOS App Development under Development as the provisioning profile type, and then select Continue.
Next, select the app ID you created from the App ID drop-down list, and select Continue.
In the Select certificates window, select the development certificate that you use for code signing, and select Continue. This certificate isn't the push certificate you created. If one does not exist, you must create it. If a certificate does exist, skip to the next step. To create a development certificate if one does not exist:
- If you see No Certificates are available, select Create Certificate.
- In the Software section, select Apple Development. Then select Continue.
- In the Create a New Certificate screen, select Choose File.
- Browse to the Certificate Signing Request certificate you created earlier, select it, and then select Open.
- Select Continue.
- Download the development certificate, and remember the location to which it's saved.
Return to the Certificates, Identifiers & Profiles page, select Profiles from the left menu, and then select + to create a new profile. The Register a New Provisioning Profile screen appears.
In the Select certificates window, select the development certificate that you just created. Then select Continue.
Next, select the devices to use for testing, and select Continue.
Finally, choose a name for the profile in Provisioning Profile Name, and select Generate.
When the new provisioning profile is created, select Download. Remember the location to which it's saved.
Browse to the location of the provisioning profile, and then double-click it to install it on your Xcode development machine.
Create a notification hub
In this section, you create a notification hub and configure authentication with APNs by using either the .p12 push certificate or token-based authentication. If you want to use a notification hub that you've already created, you can skip to step 5.
Sign in to the Azure portal.
Select All services on the left menu, and then select Notification Hubs in the Mobile section. Select the star icon next to the service name to add the service to the FAVORITES section on the left menu. After you add Notification Hubs to FAVORITES, select it on the left menu.
On the Notification Hubs page, select Add on the toolbar.
On the Notification Hub page, do the following steps:
Enter a name in Notification Hub.
Enter a name in Create a new namespace. A namespace contains one or more hubs.
Select a value from the Location drop-down list box. This value specifies the location in which you want to create the hub.
Select an existing resource group in Resource Group, or create a name for a new resource group.
Select Create.
Select Notifications (the bell icon), and then select Go to resource. You can also refresh the list on the Notification Hubs page and select your hub.
Select Access Policies from the list. Note that the two connection strings are available to you. You'll need them later to handle push notifications.
Important
Do not use the DefaultFullSharedAccessSignature policy in your application. This is meant to be used in your back end only.
Configure your notification hub with APNs information
Under Notification Services, select Apple (APNS) then follow the appropriate steps based on the approach you chose previously in the Creating a Certificate for Notification Hubs section.
Note
If you build your app with App Store or Ad-Hoc distribution profile, use the Production for Application Mode. This will allow your device to send push notifications to users who purchased your app from the store.
OPTION 1: Using a .p12 push certificate
Select Certificate.
Select the file icon.
Select the .p12 file that you exported earlier, and then select Open.
If required, specify the correct password.
Select Sandbox mode.
Select Save.
OPTION 2: Using token-based authentication
Select Token.
Enter the following values that you acquired earlier:
- Key ID
- Bundle ID
- Team ID
- Token
Choose Sandbox
Select Save.
You've now configured your notification hub with APNs. You also have the connection strings to register your app and send push notifications.
Connect your app to the notification hub
Create a new project
In Visual Studio, create a new iOS project and select the Single View App template, and click Next
Enter your App Name and Organization identifier, then click Next, then Create
From the Solution view, double-click Info.plist and under Identity make sure your Bundle Identifier matches the one used when creating your provisioning profile. Under Signing ensure that your Developer account is selected under Team, 'Automatically manage signing' is selected and your Signing Certificate and Provisioning Profile are automatically selected.
From the Solution view, double-click the
Entitlements.plist
and ensure that Enable Push Notifications is checked.Add the Azure Messaging package. In the Solution view, right-click the project and select Add > Add NuGet Packages. Search for Xamarin.Azure.NotificationHubs.iOS and add the package to your project.
Add a new file to your class, name it
Constants.cs
and add the following variables and replace the string literal placeholders with thehubname
and theDefaultListenSharedAccessSignature
noted earlier.In
AppDelegate.cs
, add the following using statement:Create an implementation of the
MSNotificationHubDelegate
in theAppDelegate.cs
:In
AppDelegate.cs
, updateFinishedLaunching()
to match the following code:In
AppDelegate.cs
, implement theDidReceivePushNotification
method for theAzureNotificationHubListener
class:Run the app on your device.
Send test push notifications
You can test receiving notifications in your app with the Test Send option in the Azure portal. It sends a test push notification to your device.
Push notifications are normally sent in a back-end service like Mobile Apps or ASP.NET using a compatible library. If a library is not available for your back-end, you can also use the REST API directly to send notification messages.
Next steps
In this tutorial, you sent broadcast notifications to all your iOS devices registered with the backend. To learn how to push notifications to specific iOS devices, advance to the following tutorial:
Due to the robust security within Apple’s new macOS operating system, there is a high emphasis on data protection. Whether you’re simply logging in, downloading new software, or trying to delete files or apps from the hard drive, you will always need to input your Mac password. Here are a few ways you can remember or reset it and get back to using your Mac.
How to avoid forgetting passwords?
Often when Mac users forget their passwords, it’s the consequence of having a cluttered Mac. With an overload of information to sieve through every day, people have a tendency to forget information. So, first and foremost, you should clean up your Mac to make sure your new password is the one entering you into a tidy and organised computer.
With CleanMyMac X, you can remove large and unwanted files, organising your digital folders and clearing your physical headspace. With its smart, one-click cleaning approach and powerful scanning, you can swiftly dispose of useless documents and apps which may even be slowing your Mac down. With CleanMyMac, you can launch a Smart Scan, removing systems junk, photo and file duplicates, and everything else that will clog up your Mac.
In addition, this amazing tool is free to download, so what are you waiting for?
How to reset a password
Get a password hint
Before resetting your password, you should always check to see if the password hint jogs your memory. The ‘hint’ is a phrase you entered relating to the password when you first set it up, and is triggered once you make 3 incorrect password attempts:
- Open System Preferences (the app with the cog icon).
- Select ‘Users & Groups.’
- Click the Lock icon in the bottom left to make changes.
- Press the Return key 3 times.
The screen will shake each time you press Return, with the third shake generating the password hint which will appear below the Password field. Hopefully this initiates a Eureka Moment making you remember the Login and brings an end to the password perils.
Sometimes though, the hint doesn’t show up. That’s because the Mac wasn’t set up to show password hints in the Login Options – only modified by logging into your Mac. Fortunately, there are an array of other solutions to finding your password.
Change password from another account
In the event that you happen to share your Mac with another person, and they have their own account, you can use their Login to reset your password. Or, if you have a different account on the Mac that you know the password to, you can recover your Mac admin password by following these steps:
- Click on the Apple logo in the top left of the tools bar and click Log Out.
- Select the alternative account and enter the password.
- Open System Preferences > Users & Groups.
- Click the Lock icon in the bottom left.
- Enter the password again.
- In the Sidebar, select the account with the missing password.
- Click change password.
- Fill in the New Password, Verify and Password Hint fields.
- Click Change Password.
Now, the password for that account has been changed, allowing you to log in using the new password. However, this doesn’t change the password for the Keychain (macOS’s password management system), and you’ll be asked when you log into the account to update the keychain password. This requires you to enter the old forgotten password, so you’ll have to click ‘Create New Keychain’.
This introduces a further problem, because if the other user isn’t the registered Admin, they won’t be able to change the password for you. Luckily, there is an alternative solution to recovering your password.
Use Recovery Mode
Mac Update Keychain Password Manager
Apple provides a tool to replace a Mac’s password through bypassing all of the previous steps. This is the best option if you don’t have a password hint, can’t log in via another account and have completely forgotten your password.
Mac Update Keychain Password
- Turn off your Mac.
- Press the power button whilst holding Command + R.
- The Mac will boot into Recovery Mode – when you see the load bar appear you can let go of the keys.
- Select ‘Disk Utility’ and press Continue.
- Go to Utilities > Terminal.
- Enter ‘resetpassword’ and press the Return key.
- Select the main hard drive.
- Select the User Account (the account you’d like to change).
- Enter a new password and create a password hint.
- Click Save – a warning will appear that the Keychain Password hasn’t changed. Click OK.
- Shut Down your Mac and start it up again. Now you can log in using the new password.
Protect Your Data
Mac Update Keychain Password Settings
Due to the fact Recovery Mode provides a nifty means to resetting the Mac password, you may be wary that anyone can hack your Mac – and once someone accesses your Mac, you’ve usually lost control over it. So, it’s a good job there’s some interventions you can make to prevent this happening.
The best way to protect your data is to active FileVault encryption. This means that the Password Reset option won’t become available unless you unlock it with Disk Utility. To turn it on and set it up:
- Choose Apple > System Preferences > Security & Privacy.
- Click the FileVault tab.
- Click the Lock icon, and enter Login credentials.
- Click Turn on FileVault.
Once done, you will receive a Recovery Key and a password, which you should take note of. If you lose these, your data won’t be able to be recovered and will be lost forever.
Another effective way to protect the data on your Mac is to download tried and tested app CleanMyMac X. With automatic clean-ups and regular system monitors, your data is continuously observed and safeguarded from any piracy or hacking.
Use Target Disk Mode
If all else fails, Target Disk Mode can help you recover whatever you can from the lost Mac. Using another Mac, you can access the hard drive on the lost Mac and save any wanted data.
- Shut down the Mac.
- Connect to another Mac using a FireWire or Thunderbolt cable.
- Start up your Mac and hold the T key while it loads.
- This activates Target Disk Mode.
The hard drive from the lost Mac should now appear, allowing you to recover and save wanted data onto the new Mac.
Thanks for reading and stay tuned!