Notes
1- You do not need an Apple Developer Account to start developing iOS Apps. The documentation and tools are free to download with your Apple ID. You can also sign and install apps on your personal devices using that same Apple ID. If you want to distribute or sell apps on the App Store, you need to enroll the Apple Developer Program starting at 99 USD (This is the price at the time of writing and may change). This will also add code-level support incidents and beta testing for your apps via TestFlight.
2- Creating an Apple ID without a credit card requires a short process. If you don't mind associating a payment method as part of the sign up, go to https://appleid.apple.com/
UILabels are views which can be used to display one or many lines of text. It contains multiple ways of stylizing text, such as shadows, text colors, and fonts.
UILabels can also display Attributed Strings, which is text + inline markup to apply styles to portions of the text.
UILabel does not conform to the UIAppearance protocol, so you cannot use UIAppearance proxy methods to customise appearance of UILabels. See this discussion for more.
Apple Developer reference here
A button’s type defines its basic appearance and behavior. After creating a button, you cannot change its type. The most commonly used button types are the Custom and System types, but use the other types when appropriate
UIButtonTypeCustom
No button style.
UIButtonTypeSystem
A system style button, such as those shown in navigation bars and toolbars.
UIButtonTypeDetailDisclosure
A detail disclosure button.
UIButtonTypeInfoLight
An information button that has a light background.
UIButtonTypeInfoDark
An information button that has a dark background.
UIButtonTypeContactAdd
A contact add button.
When creating a custom button—that is a button with the type custom—the frame of the button is set to (0, 0, 0, 0) initially. Before adding the button to your interface, you should update the frame to a more appropriate value.
Do not confuse UILocalNotification with push notifications. UILocalNotification is triggered by your device, and when scheduled, is copied to the system.
Links:
The source code for Reachability.h
and Reachability.m
can be found on Apple's developer documentation site.
Unlike other platforms, Apple is yet to provide a standard set of APIs to determine an iOS device's network status and offer only these code examples linked above. The source file change over time, but once imported into an app project, they are seldom updated by the developers.
For this reason most app developers tend to use one of the many Github/Cocoapod maintained libraries for reachability.
Apple also recommends, for requests made at the user’s behest, that you always attempt a connection first, before using Reachability/SCNetworkReachability to diagnose the failure or to wait for the connection to return.
UITableView
is a subclass of UIScrollView
. Classes that follow the UITableViewDelegate
protocol also follow the UIScrollViewDelegate
protocol. UITableView
can be useful for showing long or indeterminate lists through its cells, whilst UIScrollView
is better for when the size of the views to be shown is known beforehand.
The UIView class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content.
A
UIAlertController
object displays an alert message to the user. This class replaces theUIActionSheet
andUIAlertView
classes for displaying alerts. After configuring the alert controller with the actions and style you want, present it using thepresentViewController:animated:completion:
method.
CAAnimation is an abstract animation class. It provides the basic support for the CAMediaTiming and CAAction protocols. To animate Core Animation layers or Scene Kit objects, create instances of the concrete subclasses CABasicAnimation, CAKeyframeAnimation, CAAnimationGroup, or CATransition.
From the documentation:
The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This navigation interface makes it possible to present your data efficiently and makes it easier for the user to navigate that content. You generally use this class as-is but you may also subclass to customize the class behavior.
Whenever you do something on a separate thread, which happens when using queues, it's important to maintain thread safety. Some methods, in particular ones for UIView
s, may not work and/or crash on threads other than main thread. Also, make sure not to change anything (variables, properties, etc.) that is also being used on the main thread, unless you are accounting for this change
startPoint
and endPoint
to change the orientation of the CAGradientLayer
.locations
to affect the spread/positions of the colors.From Apple: Creating a Custom View That Renders in Interface Builder
Apple developer topic for UIImage
UIWebView Delegate functions:-
Objective-C Declerations
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType;
- (void)webView:(UIWebView *)webView
didFailLoadWithError:(NSError *)error;
- (void)webViewDidFinishLoad:(UIWebView *)webView;
- (void)webViewDidStartLoad:(UIWebView *)webView;
There are different types of date format that you can set: Here is full list of them.
Format | Meaning/Description | Example1 | Example2 |
---|---|---|---|
y | A year with at least 1 digit. | 175 AD → “175” | 2016 AD → “2016” |
yy | A year with exactly 2 digits. | 5 AD → “05” | 2016 AD → “16” |
yyy | A year with at least 3 digits. | 5 AD → “005” | 2016 AD → “2016” |
yyyy | A year with at least 4 digits. | 5 AD → “0005” | 2016 AD → “2016” |
M | A month with at least 1 digit. | July → “7” | "November" → "11" |
MM | A month with at least 2 digits. | July → “07” | "November" → "11" |
MMM | Three letter month abbreviation. | July → “Jul” | "November" → "Nov" |
MMMM | Full name of month. | July → “July” | "November" → "November" |
MMMMM | One letter month abbreviation(Jan,June,July all will have 'J'). | July → “J” | "November" → "N" |
d | Day with at least one digit. | 8 → “8” | 29 → “29” |
dd | Day with at least two digits. | 8 → “08” | 29 → “29” |
“E”, “EE”, or”EEE” | 3 letter day abbreviation of day name. | Monday → “Mon” | Thursday → “Thu” |
EEEE | Full Day name. | Monday → “Monday” | Thursday → “Thursday” |
EEEEE | 1 letter day abbreviation of day name.(Thu and Tue will be 'T') | Monday → “M” | Thursday → “T” |
EEEEEE | 2 letter day abbreviation of day name. | Monday → “Mo” | Thursday → “Th” |
a | Period of day (AM/PM). | 10 PM → “PM” | 2 AM → “AM” |
h | A 1-12 based hour with at least 1 digit. | 10 PM → “10” | 2 AM → “2” |
hh | A 1-12 based hour with at least 2 digits. | 10 PM → “10” | 2 AM → “02” |
H | A 0-23 based hour with at least 1 digit. | 10 PM → “14” | 2 AM → “2” |
HH | A 0-23 based hour with at least 2 digits. | 10 PM → “14” | 2 AM → “02” |
m | A minute with at least 1 digit. | 7 → “7” | 29 → “29” |
mm | A minute with at least 2 digits. | 7 → “07” | 29 → “29” |
s | A second with at least 1 digit. | 7 → “7” | 29 → “29” |
ss | A second with at least 2 digits. | 7 → “07” | 29 → “29” |
There are many more, for getting different time based on zone(z), for getting time with millisecond details(S), etc.
Referencing self.navigationItem
assumes that the UIViewController is embedded inside a UINavigationController.
An NSNotificationCenter object (or simply, notification center) provides a mechanism for broadcasting information within a program. An NSNotificationCenter object is essentially a notification dispatch table.
For more info, check out the Apple Documentation here
Beacons are IOT objects. We are focusing on those which conform to iBeacon protocol a Apple standard. Each beacon is a one way device which transmits 3 things
We can scan iBeacons by setting up our CLLocation manager object to scan for beacons for particular UUID. All beacons with the given UUID will be scanned.
CLLocation manager also gives call on enter and exit of beacon region.
The NSURLSession class and related classes provide an API for downloading content. This API provides a rich set of delegate methods for supporting authentication and gives your app the ability to perform background downloads when your app is not running or, in iOS, while your app is suspended.
At a high level, NSURLSession is based around the concept of sessions and tasks. A task represents a single request for a single URL (or a single upload to a single URL). A session is a group of related requests.
The operating system provides a single preexisting session—the shared session, which basically works like NSURLConnection. Additionally, you can create your own sessions in your app as needed.
Different apps use sessions in different ways. Many apps create a single session on launch and just keep reusing it. Other apps benefit from being able to cancel a group of related tasks (e.g. a web browser canceling all outstanding requests when you close a tab), and thus create one session to hold each group of related requests.
The first step when using NSURLSession is to create a session configuration object. The (usually) reusable object contains various session settings that you can tweak for your particular needs, such as maximum concurrency, extra headers to send with each request, whether to allow requests to be sent over the cellular radio (iOS only), timeouts, credential storage, minimum TLS version, and even proxy settings.
There are three types of session configurations, depending on how you want the resulting session to behave:
When you create a background configuration, you must provide a session identifier that allows you to reassociate the background session later (if your app exits or is suspended or terminated by the OS). You must not have more than one instance of a session with the same identifier active in your app, so as a rule, these configurations are not reusable. All other session configurations can be reused to create as many sessions as you want. So if you need to create multiple sessions with similar settings, you can create the configuration once and reuse it every time you create a new session.
After you create a session, you can create tasks in that session. There are three types of tasks:
Each of these types lets you obtain the response data in a couple of different ways—either by using block-based callbacks or by providing a delegate on the session and implementing delegate methods.
Additionally NSURLSession lets you provide delegate methods for handling authentication, performing custom TLS certificate handling (both for client certificates and server validation), changing the caching behavior, and so on.
UIWebView
/WKWebView
should open the app.An NSTimer
allows you to send a message to a target after a specified period of time elapses.
The CGContextRef opaque type represents a Quartz 2D drawing destination. A graphics context contains drawing parameters and all device-specific information needed to render the paint on a page to the destination, whether the destination is a window in an application, a bitmap image, a PDF document, or a printer.
NSUserDefault which are used to store all type of DataType, and you can get its value anywhere in the class of app. NSUserDefault
Apple Developer reference here
KVC :- Key-Value Coding
Normally instance variables are accessed through properties or accessors but KVC gives another way to access variables in form of strings. In this way your class acts like a dictionary and your property name for example “age” becomes key and value that property holds becomes value for that key.
For example, you have employee class with "age" property. Normally we access like this.
emp.age = @”20″;
NSString age = emp.age;
But KVC works like this:
[emp valueForKey:@"age"];
[emp setValue:@"25" forKey:@"age"];
KVO :- Key-Value Observer
The mechanism through which objects are notified when there is change in any of property is called KVO. Ex.:keyboard notification
For example, person object is interested in getting notification when accountBalance property is changed in BankAccount object. To achieve this, Person Object must register as an observer of the BankAccount’s accountBalance property by sending an addObserver: forKeyPath: options: context: message.
The CAShapeLayer class draws a cubic Bezier spline in its coordinate space. The shape is composited between the layer's contents and its first sublayer.
To save the UUID we can use SSKeychainUtility. Example can be found on Github page
Categories can be used to override methods of a class. Even if the method is actually private. The overridden method cannot be accessed from the category or anywhere else. So it's important to make sure when adding methods to an existing class, that those methods don't exist already.
In iOS9 and above your app must list any URL schemes it will want to query. This is done by adding LSApplicationQueriesSchemes
to Info.plist
iOS has built-in support for the tel
, http
/https
,sms
, mailto
, facetime
schemes. It also supports http–based URLs for Youtube
, Maps
and iTunes
apps.
Examples of built-in URL schemes:
tel: tel://123456890
or tel:123456890
http: http://www.google.com
facetime: facetime://[email protected]
mailto: mailto://[email protected]
sms: sms://123456890
or sms:123456890
Youtube: https://www.youtube.com/watch?v=-eCaif2QKfA
Maps:
Using address: http://maps.apple.com/?address=1,Infinite+Loop,Cupertino,California
Using coordinates: http://maps.apple.com/?ll=46.683155557,6.683155557
iTunes: https://itunes.apple.com/us/artist/randy-newman/id200900
Note: Not all special characters are supported in tel
scheme (for example *
or #
). This is done because of security concerns to prevent users from unauthorized redirect of calls, so in this case Phone
app won't be opened.
Adding a new RLMObject to an existing Realm - Schema and Migrations
Adding new model classes to a Realm does not require a migration or a schema version bump; only making changes to an existing Realm.
// Content size category constants
UIContentSizeCategoryExtraSmall
UIContentSizeCategorySmall
UIContentSizeCategoryMedium
UIContentSizeCategoryLarge
UIContentSizeCategoryExtraLarge
UIContentSizeCategoryExtraExtraLarge
UIContentSizeCategoryExtraExtraExtraLarge
// Accessibility sizes
UIContentSizeCategoryAccessibilityMedium
UIContentSizeCategoryAccessibilityLarge
UIContentSizeCategoryAccessibilityExtraLarge
UIContentSizeCategoryAccessibilityExtraExtraLarge
UIContentSizeCategoryAccessibilityExtraExtraExtraLarge
Using the SWRevealViewController class as the main navigation might not always result in the best user experience. If the sidebar contains only 5 or less entries (or the content can be compressed into 5 or less entries), you should consider using the default tab bar.
The tab bar is intuitive and allows the user to quickly change between views/contexts. On the other hand, the sidebar navigation can perform more actions than switching the view/context and uses less space when collapsed.
For more information check out Apple's iOS Human Interface Guidelines.
As you build adaptive apps, keep in mind the limitations of size classes: they are generalizations, not specific guides for exact pixel sizes or devices. Never attempt to determine what device your app is running on, or whether it's in a split-screen mode, based on the size classes.
Instead, make high-level layout decisions on size class, and use Auto Layout to change precise view frames. (See also the UIViewController method viewWillTransition(to:with:)
for a more precise notification of how big a controller's view will be after a transition.)
IBOutlet is neither a reserved word nor a variable or class, is syntactic sugar for Interface Builder. After the Objective-C source code is pre-processed it is resolved to nothing.
In Swift it's resolved as nil.
It's declared in <UIKit/UINibDeclarations.h>
as
#ifndef IBOutlet
#define IBOutlet
#endif
UISplitViewController
is a container class like UITabViewController
, UINavigationController
. It separates the main view into two View Controllers masterViewController(PrimaryViewController) and detailViewController(SecondaryViewController). we can send an array with two view controllers and Apple recommends to to UISplitViewController
as a rootviewcontroller for your application. To interact between the viewcontrolers I use NSNotificationCenter
.
In iOS 8 and later, you can use the UISplitViewController
class on all iOS devices, in previous versions of iOS, the class is available only on iPad.
UISplitViewController
is a container class like UITabViewController
, UINavigationController
. It separates the main view into two UIViewControllers
masterViewController
(PrimaryViewController) and detailViewController
(SecondaryViewController). we can send an NSArray
with two UIViewControllers
and Apple recommends UISplitViewController
as a rootviewcontroller for your application. To interact between the UIViewControllers
I use NSNotificationCenter
.
The UIDevice class provides a Singleton instance representing the current device. From this instance you can obtain information about the device such as assigned name, device model, and operating-system name and version.
Run xcodebuild
from the directory containing your project to build an Xcode project. To build an Xcode workspace, you must pass both the -workspace and -scheme options to define the build. The parameters of the scheme will
control which targets are built and how they are built, although you may
pass other options to xcodebuild to override some parameters of the
scheme.
import AVKit, import AVFoundation.
Useful Apple documentation with examples and clarification.
The App Transport Security is a security feature in iOS and macOS. It prevents apps from establishing unsecured connections. By default, apps can only use secure HTTPS connections.
If an app needs to connect to a server via HTTP, exceptions must be defined in the Info.plist
. (see the examples for more information about that)
Note: In 2017, Apple will enforce ATS. That means, that you can no longer upload apps that have ATS-exceptions defined in the Info.plist
. If you can provide good arguments, why you have to use HTTP, you can contact Apple and they might allow you to define exceptions. (Source: WWDC 2016 - Session 706)
More information on the App Transport Security configuration can be found in the CocoaKeys Documentation.
UIDatePicker
does not inherit from UIPickerView
, but it manages a custom picker-view object as a subview.
Ride Booking (e.g. Get me a ride to New York via MyApp)
Messaging (e.g. Send a text to John using MyApp)
Photo Search (e.g. Look for beach photos taken last summer in MyApp)
Payments (e.g. Send $20 to John for dinner last night using MyApp)
VoIP Calling (e.g. Call Mike on my MyApp)
Workouts (e.g. Start my daily run workout from MyApp)
Climate and Radio (specifically designed for CarPlay, e.g. Set the heater to 72 degrees)
For more details ( Size Classes and Adaptivity through Storyboard) of using auto layout for adaptivity in iOS, we can follow the apple developer site link.
We can also add constraints Programatically using Visual Format Language as described here at apple developer site.
iOS stores private information such as passwords, encryption keys, certificates, and identities in a secure storage area called the Keychain. This storage area is managed completely by a co-processor called the Secure Enclave, which is embedded inside the application processor. Because the Keychain is sandboxed on iOS, keychain items may only be retrieved by the application that put them there in the first place.
In some cases you must turn on Keychain Sharing in Xcode capabilities in order to avoid errors.
In order to interact with the keychain, we use a c framework called Keychain Services. For more information, see Apple's Keychain Services Programming Guide.
Because Keychain Services is below the Foundation
level, it is restricted to using CoreFoundation
types. As a result, most objects are internally represented as CFDictionary
s holding CFString
s as their keys and a variety of CoreFoundation
types as their values.
While Keychain Services is included as a part of the Security
framework, importing Foundation
is usually a good option since it includes some helper functions in the backend.
Additionally, if you don't want to deal with Keychain Services directly, Apple provides the Generic Keychain Swift sample project that provides Swift types that use Keychain Services behind the scenes.
Content Compression Resistance Priority
This value determines how resistant a view is to being compressed, or shrunk. A higher value here means the view will be less likely to be compressed and more likely to stay the same.
Content Hugging Priority
This value determines how resistant a view is to being expanded. You can imagine “hugging” here to mean “size to fit” – the bounds of the view will “hug” or be close to the intrinsic content size. A higher value here means the view will be less likely to grow and more likely to stay the same.
Please see the Apple Documentation for more information regarding privacy.
Make sure the Music app is available in your iPhone. It will not work in the simulator.
MPVolumeView only shows up when building and running on an actual iOS device and will not work in a simulator.
Once, current document gets approved, will add so many enhancement for other array utilites also. This is my first document and need your assistance and approval in my effort.
Components:
Component duties:
Model | View | Presenter |
---|---|---|
Communicates with DB layer | Renders data | Performs queries to the Model |
Raising appropriate events | Receives events | Formats data from Model |
Very basic validation logic | Sends formatted data to the View | |
Complex validation logic | ||
Differences between MVC and MVP:
Pros:
Cons
An import thing to keep in mind when using UIKit Dynamics is views that are positioned by the animator cannot readily be positioned by other common iOS layout methods.
Newcomers to UIKit Dynamics often struggle with this important caveat. Placing constraints on a view that is also an item of a UIDynamicBehavior
will likely cause confusion as a both the auto layout engine and the dynamic animator engine fight over the appropriate position. Similarly, attempting to set the frame directly of a view being controlled by the animator will typically result in jittery animation and unexpected placement. Adding a view as an item to a UIDynamicBehavior
means that the animator will take on the responsibility of positioning a view and as such changes of view positions should be implemented through the animator.
A view's frame that is being updated by a dynamic animator can be set, but that should be immediately followed by messaging the animator to update the animator's internal model of the view hierarchy. For example, if I have UILabel
, label
that is an item of a UIGravityBehavior
I can move it to the top of the screen to watch it fall again by saying:
label.frame = CGRect(x: 0.0, y: 0.0, width: label.intrinsicContentSize.width, height: label.intrinsicContentSize.height)
dynamicAnimator.updateItem(usingCurrentState: label)
self.label.frame = CGRectMake(0.0, 0.0, self.label.intrinsicContentSize.width, self.label.intrinsicContentSize.height);
[self.dynamicAnimator updateItemUsingCurrentState: self.label];
After which the animator will apply the gravity behavior from the label's new location.
Another common technique is to use UIDynamicBehaviors
to position views. For example if positioning a view under a touch event is desired, creating a UIAttachmentBehavior
and updating its anchorPoint
in either touchesMoved
or a UIGestureRecognizer
's action is an effective strategy.
func SearchBLE(){
cb_manager.scanForPeripherals(withServices:[service_uuid], options: nil)
StopSearchBLE()
}
func centralManager(_ central: CBCentralManager, didConnect peripheral:
CBPeripheral) {
peripheral.delegate = self
peripheral.discoverServices(nil)
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
for service in peripheral.services! {
print("Service: \(service)\n error: \(error)")
}
}
Add this extensions to your class
protocol DataConvertible {
init?(data: Data)
var data: Data { get }
}
extension DataConvertible {
init?(data: Data) {
guard data.count == MemoryLayout<Self>.size else { return nil }
self = data.withUnsafeBytes { $0.pointee }
}
var data: Data {
var value = self
return Data(buffer: UnsafeBufferPointer(start: &value, count: 1))
}
}
extension UInt16 : DataConvertible {
init?(data: Data) {
guard data.count == MemoryLayout<UInt16>.size else { return nil }
self = data.withUnsafeBytes { $0.pointee }
}
var data: Data {
var value = CFSwapInt16HostToBig(self)
return Data(buffer: UnsafeBufferPointer(start: &value, count: 1))
}
}
$ git clone https://github.com/sqlcipher/sqlcipher.git
Select the Build Settings pane. In the search field, type in "Header Search Paths". Double-click on the field under the target column and add the following path: $(PROJECT_DIR)/sqlcipher/src
Start typing "Other Linker Flags" into the search field until the setting appears, double click to edit it, and add the following value: $(BUILT_PRODUCTS_DIR)/libsqlcipher.a
Start typing "Other C Flags" into the search field until the setting appears, double click to edit it, and in the pop-up add the following value: -DSQLITE_HAS_CODEC
Expand Target Dependencies and click on the + button at the end of the list. In the browser that opens, select the sqlcipher static library target:
Always remember the following mention from Apple.
In a horizontally compact environment, modal view controllers are always presented full-screen. In a horizontally regular environment, there are several different presentation options.
Supported activity types must be defined in your app's Info.plist
file under the NSUserActivityTypes
key. Activities are tied to your Developer Team ID, meaning that activity coordination is restricted between apps that have the same Team ID (e.g. "Safari" could not accept a Handoff activity from "Chrome" or vice versa).
Marking an activity as current using becomeCurrent
makes it available for Handoff or Spotlight Indexing. Only one activity may be current at a time. You may mark an activity as inactive without invalidating by calling resignCurrent
.
If you invalidate
an activity, the same instance may not be made current again.
Do not mark an activity as current when providing it for SiriKit.
Activities are not to be used as a general-purpose indexing mechanism within your app. Instead, they should only be used in response to user-initiated actions. To index all content in your app, use CoreSpotlight.
Firstly, as you are dealing with multiple flows, this is where Storyboards can be used effectively. By default your Application uses Main.storyboard
for your primary flow. Your onboarding/alternative flow can be contained in a secondary storyboard, eg. Onboarding.storyboard
This has a number of advantages:
When your App launches, you can determine which flow should be presented. The logic for this can be contained in your AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let isFirstRun = true // logic to determine goes here
if isFirstRun {
showOnboarding()
}
return true
}
In order to show the Onboarding flow, it's worth considering how you'd like to handle the experience of dismissing it once the person using it has completed the journey, and which is semantically correct for what you are trying to create.
The two main approaches are:
The implementation of this should be contained in an extension to AppDelegate.