Add data to native iPhone app from our application in iPhone - iphone

If I develop an app through which we can choose a date and time and enter a text and that text should be added for the corresponding date and time of the native I phone calendar. Is there any way to achieve that?

Yes, should be possible using the EventKit framework (introduced in iOS 4.0).
EKEvent is the class you're probably looking for.

I use this code
EKEventStore *eventStore = [[EKEventStore alloc] init];
if ([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)])
{
// the selector is available, so we must be on iOS 6 or newer
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error)
{
// display error message here
}
else if (!granted)
{
// display access denied error message here
}
else
{
// access granted
// ***** do the important stuff here *****
}
});
}];
}
else
{
// this code runs in iOS 4 or iOS 5
// ***** do the important stuff here *****
}

Related

iPhone App Crash with error [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:]

I have an iPhone App in the app store which is using Touch ID. If Touch ID is enabled, the user is authenticated with it, else user needs to enter his PIN to login to the application.
After IOS 10.1 release, when I checked the crash report, the crash count has increased. From the crash report, it is pointing on [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] and when I opened the app in Xcode, it is focussing on [self dismissViewControllerAnimated:YES completion:nil];.
The code I have written is as below:
-(void) showTouchIDAuthentication{
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = #"Authenticate using your finger to access My Account Menu.";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"User is authenticated successfully");
[self dismissViewControllerAnimated:YES completion:nil];
} else {
}];
}
}
When I tested in iPhone 6, IOS 10, everything is working fine. Don't know how to simulate the issue.
Can anyone please figure out if I am missing something? Please help me out in resolving this crash issue.
Usually completion handlers are not running on main thread. All UI related stuff must be done on main thread (including dismissing a view controller).
I suggest to add the dismiss line on a main thread block like this:
-(void) showTouchIDAuthentication{
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = #"Authenticate using your finger to access My Account Menu.";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"User is authenticated successfully");
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[self dismissViewControllerAnimated:YES completion:nil];
}];
} else {
}];
}
}

show app name on facebook share iPhone

I am using facebook.framework i want to share image using native facebook Dialog of iOS 6.0
I can share image but i want to show my app name.... like currently it showing via ios....
I6+
+65 want to show app name..Like via xyz... I am using below code.....
- (IBAction)publishButtonAction:(id)sender {
// Try and present the iOS Share Sheet
[FBDialogs
presentOSIntegratedShareDialogModallyFrom:self
initialText:#"" image:[UIImage imageNamed:#"iossdk_logo.png"]
url:[NSURL URLWithString:#"https://developers.facebook.com/ios"]
handler:^(FBOSIntegratedShareDialogResult result, NSError *error) {
NSString *alertText = #"";
if ([[error userInfo][FBErrorDialogReasonKey]
isEqualToString:FBErrorDialogNotSupported]) {
alertText = #"iOS Share Sheet not supported.";
} else if (error) {
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
} else if (result == FBNativeDialogResultSucceeded) {
alertText = #"Posted successfully.";
}
if (![alertText isEqualToString:#""]) {
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}
}];
}
Unfortunately, you can't show your App Name if you want to use Facebook.framework and the iOS 6 default share dialog.
The only way to achieve this is to register an app on Facebook Developers and handle every connection/request using their iOS SDK.
Facebook.framework is the most straightforward way to deal with Facebook APIs but you have to renounce to your app name. Otherwise, you can take the harder way and build your app from scratch so you'll be able to show your app name. More info here: Facebook Share Dialog.

FBDialogs presentShareDialog does not work in both 5.1 and 6.1

id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:#"https://example.com/book/Snow-Crash.html"
forKey:#"book"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"books.reads"
previewPropertyName:#"book"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
I use the above codes to present a facebook shareDialog in my application ,but it does not work in both ios 5.1 and 6.1.I want to know the reason.
From my understanding as of now (I might be wrong), this code invokes the facebook native iOS app. If you are testing this on the simulator and don't have the iOS app installed, this will not work. It is unlikely you will be able to test this on the simulator. Try it on a real device that has the facebook iOS app installed.
Do you have the latest Facebook app installed?
Also, you're trying to post an open graph action using facebook's example action, which I'm not sure even exists. If you have registered custom open graph actions with you app, I suggest you modify your code to invoke it instead. If you don't have custom actions, I suggest starting with posting simple urls to see if it works for you.
Use:
NSURL* url = [NSURL URLWithString:#"https://developers.facebook.com/"];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
And lastly I suggest you read this: https://developers.facebook.com/ios/share-dialog/

i want to store some data in "EverNote" through our app

i want to store some data in "EverNote" through our app either (image or text or both).
I googled, i got some guidance like EverNote SDK and i got the EverNoteCounter Sample also(When i run this, when i click getCount button it shows an alert message "Could not authenticate").
I generated the developer token also.
But i unable to create the consumerKey,consumerSecret. And also i did not find how to store our data to evernote from our app.
I got some links like this one
but when i go through that link it says( HTTP method GET is not supported by this URL)
I able to authenticate with the EVERNOTE and i able to get the number of notebooks in that Account.
I am using sqllite in my app. i am using one folder for images. Sqllite have the images links info.
How to store the data.
I used the following code to authenticate and to get the count
- (IBAction)retrieveUserNameAndNoteCount:(id)sender
{
// Create local reference to shared session singleton
EvernoteSession *session = [EvernoteSession sharedSession];
[session authenticateWithViewController:self completionHandler:^(NSError *error) {
// Authentication response is handled in this block
if (error || !session.isAuthenticated) {
// Either we couldn't authenticate or something else went wrong - inform the user
if (error) {
NSLog(#"Error authenticating with Evernote service: %#", error);
}
if (!session.isAuthenticated) {
NSLog(#"User could not be authenticated.");
}
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Error"
message:#"Could not authenticate"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] autorelease];
[alert show];
} else {
// We're authenticated!
EvernoteUserStore *userStore = [EvernoteUserStore userStore];
// Retrieve the authenticated user as an EDAMUser instance
[userStore getUserWithSuccess:^(EDAMUser *user) {
// Set usernameField (UILabel) text value to username
[usernameField setText:[user username]];
// Retrieve total note count and display it
[self countAllNotesAndSetTextField];
} failure:^(NSError *error) {
NSLog(#"Error retrieving authenticated user: %#", error);
}];
}
}];
}
- (void)countAllNotesAndSetTextField
{
// Allow access to this variable within the block context below (using __block keyword)
__block int noteCount = 0;
EvernoteNoteStore *noteStore = [EvernoteNoteStore noteStore];
[noteStore listNotebooksWithSuccess:^(NSArray *notebooks) {
for (EDAMNotebook *notebook in notebooks) {
if ([notebook guid]) {
EDAMNoteFilter *filter = [[EDAMNoteFilter alloc] init];
[filter setNotebookGuid:[notebook guid]];
[noteStore findNoteCountsWithFilter:filter withTrash:NO success:^(EDAMNoteCollectionCounts *counts) {
if (counts) {
// Get note count for the current notebook and add it to the displayed total
NSNumber *notebookCount = (NSNumber *)[[counts notebookCounts] objectForKey:[notebook guid]];
noteCount = noteCount + [notebookCount intValue];
NSString *noteCountString = [NSString stringWithFormat:#"%d", noteCount];
[noteCountField setText:noteCountString];
}
} failure:^(NSError *error) {
NSLog(#"Error while retrieving note counts: %#", error);
}];
}
}
} failure:^(NSError *error) {
NSLog(#"Error while retrieving notebooks: %#", error);
}];
}
Please suggest me the links or give me the guidance
Thanks a lot in advance
Developer token is to be used when you only need to access your own account. To get a consumer key/secret, go here : http://dev.evernote.com/documentation/cloud/ .
If you are using iOS, https://github.com/evernote/evernote-sdk-ios has a sample app that you can use once you have a consumer key and secret.
In general, there is a lot of information on dev.evernote.com.
All SDKs are located at https://github.com/evernote
Getting started guide for iOS : http://blog.evernote.com/tech/2012/05/24/evernote-sdk-integration-ios/
Did you solved it? If not, i did the following to get it work:
download and include sdk
get consumerKey and secret (if you want to access notes too, then
instead of basic you should request for full access, http://dev.evernote.com/documentation/cloud/ top right corner)
Add the URLType entry in info.plist ("Modify your application's main
plist file" chapter https://github.com/evernote/evernote-sdk-ios)
Copy the session init code (filled with consumer key and secret, the hostname should be left unchanged) and implement the two application delegate specific code
An (on-screen) viewcontroller should be passed on authenticating the user to authenticateWithViewController method, f.e. the appdelegate's rootViewController
Study this pages to understand the model hierarchy used by Evernote:
http://dev.evernote.com/documentation/cloud/chapters/data_structure.php
http://dev.evernote.com/documentation/reference/Types.html
Image could be stored as EDAMResource (Resource) in the field data and text as EDAMNote (Note) in the field content. Both is handled by Evernote SDK's EvernoteNoteStore object.

EKErrorDomain Code=1 in EventKit in ios5.0

I am getting following error in different places like when I am removing an event or when adding the an event.In that desccriptions it is showing that no calendar has been set but I debugged the event calendar and get the calendar is already set.I am confused.
Error Domain=EKErrorDomain Code=1 "No calendar has been set." UserInfo=0x756a8d0 {NSLocalizedDescription=No calendar has been set.}
Can any one suggest me if are there any chcekpoints or I am doing anything wrong?
Thanks in advance
I know the title of this question references iOS5, but I had an app running on iOS5 and greater. My iOS6 users were running into this issue for different reasons - you need to use the new iOS6 method if available to get access to the event store first.
- (void)requestAccessToEntityType:(EKEntityType)entityType completion:(EKEventStoreRequestAccessCompletionHandler)completion
Be sure to check availability of the API first, e.g.
EKEventStore* eventStore = [[EKEventStore alloc] init];
if([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)]) {
// >= iOS 6
[eventStore requestAccessToEntityType:EKEntityTypeEvent
completion:^(BOOL granted, NSError *error) {
// may return on background thread
dispatch_async(dispatch_get_main_queue(), ^{
if (granted) {
// continue
} else {
// display error
}
});
}];
} else {
// < iOS 6
// continue
}
I figured it out, try this when creating a new EKEvent:
[event setCalendar:[eventStore defaultCalendarForNewEvents]];