Monday 19 September 2016

SiriKit in iOS


   There are so many variation we found in ios 10 for app extension. I here describe one of them and it is Intent and IntentUI app extension
          
         Till now you cannot use SiriKit in ios application :(. But.......... 
         Now in ios 10 you can use sirikit in your ios application  :)
       


       
Siri is introduces from ios5. Now we can use it in our application.
 SiriKit is a new iOS developer framework that allows third-party apps from the App Store to              integrate their features with Siri.
 SiriKit is an app extension that allows any app to add a conversational UI.
 If your app  want to support sirikit then it has to support following domains:
  1. VoIP calling
  2. Messaging
  3. Payments
  4. Photo
  5. Workouts
  6. Ride booking
  7. CarPlay (automotive vendors only)
  8. Restaurant reservations (requires additional support from Apple)

Each domain represent one or more tasks. Each task can be represent an intent.each intent is represented by a custom class whose properties contain information related to the task. For example, intents in the Payments domain contain properties with the amount of money to transfer and the users involved in the transaction. When the user makes a request through Siri or Maps, the system fills an intent object with the details of the request and delivers that object to your app extension. You use the intent object to validate the request data and perform the associated task.

Intent and IntentUI 

Intent : Intent extension that receives information from the system and return the response.

IntentUI : Used to show custom user interface  to the user.

To understand Sirikit you have to understand app extension.

App extension works in this way :

If you open photos app and tap on share button you can see the instagram icon .Here Photos is a host application. when tap on share icon instagram extension open.
Here apple provided flow how all this work.





Now we focus back on sirikit:

How siri actual work we take an example of chat application.

If i say hey "send message to Prerak" then what happen.... Prerak name is not in database of siri. but its is in database of whatsapp. Now whatsapp developer share the contact details of Prerak to siri. You can share album name, workout name then siri check if there are some mission information. Siri recongnize that on message domain you have message to send. To solve this siri will ask what message you want to send to Prerak. After all this steps siri wraps all you data in intent. It then passes that intent object to your application for you to perform the logic on, and waits for a response to confirm the action with the user. If you are implementing Siri in your app, the name that users will use to summon your application, is the same as the name that is listed below your app on the home screen.

The programming part we will cover in the next blog...:)

Friday 15 April 2016

Linkdin Login in ios application

In one of my application i have to provide option that user can login though linkdn.

First of all make 

1) Add linkedin-sdk framework in your project

2) Get access token from this method:

[LISDKSessionManager createSessionWithAuth:[NSArray arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, LISDK_EMAILADDRESS_PERMISSION, nil]
                                     state:@"some state"
                                     showGoToAppStoreDialog:YES
                                               successBlock:^(NSString *returnState) {

                                                   NSLog(@"%s","success called!");
                                                   LISDKSession *session = [[LISDKSessionManager sharedInstance] session];
                                                   NSLog(@"value=%@ isvalid=%@",[session value],[session isValid] ? @"YES" : @"NO");
                                                   NSMutableString *text = [[NSMutableString alloc] initWithString:[session.accessToken description]];
                                                   [text appendString:[NSString stringWithFormat:@",state=\"%@\"",returnState]];
                                                   NSLog(@"Response label text %@",text);
                                                   _responseLabel.text = text;
                                                   self.lastError = nil;
                                                   // retain cycle here?
                                                   [self updateControlsWithResponseLabel:NO];

                                               }
                                                 errorBlock:^(NSError *error) {
                                                     NSLog(@"%s %@","error called! ", [error description]);
                                                     self.lastError = error;
                                                     //  _responseLabel.text = [error description];
                                                     [self updateControlsWithResponseLabel:YES];
                                                 }
     ];
   
3) if you want id,first-name,last-name,maiden-name,email-address after authorization you can apply this code:

   [[LISDKAPIHelper sharedInstance] apiRequest:https://www.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,email-address)
                                             method:method
                                               body:nil
                                            success:^(LISDKAPIResponse *response) {
                                                NSLog(@"success called %@", response.data);
                                                AppDelegate *myAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
                                                dispatch_sync(dispatch_get_main_queue(), ^{
                                                    [myAppDelegate showAPIResponsePage:method
                                                                                status:response.statusCode
                                                                               request:_resourceTextField.text
                                                                              response:response.data];
                                                });
                                            }
                                              error:^(LISDKAPIError *apiError) {
                                                  NSLog(@"error called %@", apiError.description);
                                                   AppDelegate *myAppDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
                                                  dispatch_sync(dispatch_get_main_queue(), ^{
                                                      LISDKAPIResponse *response = [apiError errorResponse];
                                                      NSString *errorText;
                                                      if (response) {
                                                          errorText = response.data;
                                                      }
                                                      else {
                                                          errorText = apiError.description;
                                                      }
                                                  [myAppDelegate showAPIResponsePage:[self getMethod]
                                                                              status:[apiError errorResponse].statusCode
                                                                             request:_resourceTextField.text
                                                                            response:errorText];
                                                  });
                                              }];

 
you can check your method output by this link:

https://apigee.com/console/linkedin
 

Get the crash log from console

I am developing one of application which crashes in 64 devices  which i don't have. My client is outside from company and i have to upload the build and check the log . He has to mail me crash log.

For that i apply this functionality which  anyone can use.

This function can be used to write the log in document folder and then email them.

    - (IBAction)redirectLogToDocuments
        {
            if ([MFMailComposeViewController canSendMail]==TRUE) {


            NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [allPaths objectAtIndex:0];
            NSString *pathForLog = [documentsDirectory stringByAppendingPathComponent:@"clipboard.txt"];

            freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);

            NSString *emailTitle = @"Email Log";
            // Email Content
            NSString *messageBody = @"Check Log to view from where application stop";
            // To address
            NSArray *toRecipents = [NSArray arrayWithObject:@"support@appcoda.com"];

            MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
            mc.mailComposeDelegate = self;
            [mc setSubject:emailTitle];
            [mc setMessageBody:messageBody isHTML:NO];
            mc.modalPresentationStyle = UIModalPresentationCurrentContext;
            [mc setToRecipients:toRecipents];
            NSData *fileData = [NSData dataWithContentsOfFile:pathForLog];
            [mc addAttachmentData:fileData mimeType:@"text/plain"  fileName:@"clipboard.txt"];

            // Present mail view controller on screen
            //[self presentViewController:mc animated:YES completion:nil];
            [self presentViewController:mc animated:YES completion:^{

            }];
            } else {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Please configure mail" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                [alert show];
            }

        }


  - (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
    {
        NSString *strMessage;
        switch (result)
        {
            case MFMailComposeResultCancelled:
                NSLog(@"Mail cancelled");
                strMessage = @"Mail cancelled";
                break;
            case MFMailComposeResultSaved:
                NSLog(@"Mail saved");
                strMessage = @"Mail save";
                break;
            case MFMailComposeResultSent:
                strMessage = @"Mail sent";
                NSLog(@"Mail sent");
                break;
            case MFMailComposeResultFailed:
                NSLog(@"Mail sent failure: %@", [error localizedDescription]);
                 strMessage = @"Mail sent failure";
                break;
            default:
                break;
        }
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message" message:strMessage delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissViewControllerAnimated:YES completion:NULL];
    }

Thats it you are done now you can mail yout whole log of application by mail.

Happy Coding!!!!