ref – http://www.insert.io/frameworkios8xcode6/
Let’s say we want to get a project called ADAL from the git repository and then add it to our project as an external framework for us to use.
First, let’s get the project:
git submodule add https://github.com/AzureAD/azure-activedirectory-library-for-objc adal
cd adal
git checkout tags/2.1.0
Optionally, later don’t forget to add this framework to your git, and push it.
cd ..
git add adal
git commit -m “Use ADAL git submodule at 2.1.0”
git push
Locate the ADAL project folder
the adal folder will be downloaded into your root git directory. (the one with the .git hidden folder)
You will see the ADAL project. Inside, you’ll see several folders. Locate the main ADAL folder with the source files by looking for a .xcodeproj file, along with src folder and its header/implementation files.
Drag the project over
Make sure you drag the .xcodeproj file over to your project space. Open it and you’ll see the src folders and what not. Look in the Products folder. You will see the ADAL.framework. That is what we’ll be importing into our project.
Select your Target, then Build Phases, then click on Link Binary With Libraries
Also, in Target, then Build Phases, then Target Dependencies, make sure you add the ADAL framework as well
Click on the ADAL framework and import it.
Make sure you’ve imported the framework. The run the project.
Inserting some code
Finally, in your ViewControllelr.m, import the header file and you should get no errors.
1 2 3 4 5 6 |
#import <MicrosoftAzureMobile/MicrosoftAzureMobile.h> #import "QSTodoService.h" #import <ADAL/ADAuthenticationContext.h> #import <ADAL/ADAuthenticationResult.h> #import <ADAL/ADTokenCacheItem.h> |
add some define strings for the table names in our azure cloud
1 2 |
#define ALL_ACTIVITIES_TABLENAME @"TodoItem" #define ALL_ACTIVITIES_QUERID @"allTodoItems" |
Let’s create a service so the view controller can communicate with the cloud tables
1 2 3 |
@interface LoginViewController ()<UITextFieldDelegate> @property (strong, nonatomic) QSTodoService * todoService; @end |
Set up the service with the table name and query
1 2 3 4 5 6 7 8 9 |
- (void)viewDidLoad { [super viewDidLoad]; self.todoService = [QSTodoService defaultService]; [self.todoService syncTableWithName: ALL_ACTIVITIES_TABLENAME]; [self.todoService setQuery: ALL_ACTIVITIES_QUERID]; .. .. } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
- (void) loginAndGetData { //get client of our service that communicates with the table on the cloud on a query MSClient * client = self.todoService.client; if (client.currentUser != nil) { return; } NSString *authority = @"<INSERT-AUTHORITY-HERE>"; NSString *resourceURI = @"<INSERT-RESOURCE-URI-HERE>"; NSString *clientID = @"<INSERT-CLIENT-ID-HERE>"; NSString *redirectURI = @"<INSERT-REDIRECT-URI-HERE>"; ADAuthenticationError *error; ADAuthenticationContext *authContext = [ADAuthenticationContext authenticationContextWithAuthority:authority error:&error]; NSURL *redirectUri = [[NSURL alloc]initWithString:redirectURI]; [authContext acquireTokenWithResource:resourceURI clientId:clientID redirectUri:redirectUri completionBlock:^(ADAuthenticationResult * result) { if (result.tokenCacheItem == nil) { return; } else { NSDictionary *payload = @{@"access_token" : result.tokenCacheItem.accessToken}; [client loginWithProvider:@"windowsazureactivedirectory" token:payload completion:^(MSUser *user, NSError *error) { [self refresh]; }]; } }]; } |
dyld: Library not loaded
http://stackoverflow.com/questions/24993752/os-x-framework-library-not-loaded-image-not-found
After you’d made sure there are no errors, if you run into an image not found error, it just means that in your Target, General, Embedded Binaries, click the ‘+’ button and add the ADAL ios framework from its original directory. (NOT the one you dragged into your project)