Crash while sharing to Pintrest in ios - ios

I want to share a post on Pintrest( i.e. want to pin from my app). I have used its SDK using Cocoa Pod. I'm able to pin (share) sometimes but sometimes while pinning it app crashes on random basis and getting nothing in crash log.
Can anyone tell me what is going wrong ? I'm adding the code snippet that i have used...I have used this link to install the SDK and followed this link. https://github.com/pinterest/ios-pdk
-(IBAction)pintrestButtonTapped
{
#try
{
[PDKClient configureSharedInstanceWithAppId:#"4841203782190640720"];
[[PDKClient sharedInstance] authenticateWithPermissions:#[PDKClientReadPublicPermissions,
PDKClientWritePublicPermissions,
PDKClientReadPrivatePermissions,
PDKClientWritePrivatePermissions,
PDKClientReadRelationshipsPermissions,
PDKClientWriteRelationshipsPermissions]
withSuccess:^(PDKResponseObject *responseObject)
{
[PDKPin pinWithImageURL:[NSURL URLWithString:#"https://www.respectnetwork.com/wp-content/uploads/cynja-app_store_share.jpg"]
link:[NSURL URLWithString:#"https://itunes.apple.com/us/app/cynjaspace/id1050628761?ls=1&mt=8/"]
suggestedBoardName:#"CynzaSpace"
note:kSocialMediaSharingText
withSuccess:^
{
NSLog(#"Successfully Pinned Up!!");
}
andFailure:^(NSError *error)
{
NSLog(#"UnSuccessfull");
}];
}
andFailure:^(NSError *error)
{
NSLog(#"authentication failed: %#", error);
}];
}
#catch (NSException *exception)
{
// Print exception information
NSLog( #"NSException caught" );
NSLog( #"Name: %#", exception.name);
NSLog( #"Reason: %#", exception.reason );
return;
}
}

Related

IOS/Objective-C:EventKit EKReminders compared with EKEvents

I a experimenting with EventKit and am confused by how events compare with reminders.
Do you need to obtain separate permission to access reminders and events?
I know there is such a thing as self.eventStore requestAccessToEntityType:EKEntityTypeReminder and also requestAccessToEntityType:EKEntityTypeEvent
Here are methods for both. But it seems excessive to have to ask for permission for things that are so closely related twice.
-(void)requestAccessToEvents{
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (error == nil) {
// Store the returned granted value.
self.grantedEvents = granted;
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:granted] forKey:#"eventsAccessGranted"];
}
else{
// In case of error, just log its description to the debugger.
NSLog(#"%#", [error localizedDescription]);
}
}];
}
-(void) requestAccessToReminders
{
[self.eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error)
{
if (error == nil) {
// Store the returned granted value.
self.grantedReminders = granted;
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:granted] forKey:#"remindersAccessGranted"];
}
else{
// In case of error, just log its description to the debugger.
NSLog(#"%#", [error localizedDescription]);
}
if (granted)
{
importEvents * __weak weakSelf = self;
//ensure code will be executed from the main queue
dispatch_async(dispatch_get_main_queue(), ^{
// [weakSelf aMethodToUpdateUIFetchEvents];//method located in viewController
});
}
}];
}
Thanks for any suggestions.
EKEntityTypeEvent is for events that go to the user's calendar.
EKEntityTypeReminder is for reminders that go to the user's reminders.
Each requires its own request for permission. A user might allow access to one but not the other. Ignore that the APIs are similar and related. To the user, they are two completely different things.

AdobeAssetFile: can't tracking upload progress

I'm trying to upload image to Adobe Creative Cloud using method create:folder:dataPath:contentType:progressBlock:successBlock:cancellationBlock:errorBlock of AdobeAssetFile. File upload succesfully, but I can't track upload progress with progressBlock. This block just don't invocated.
- (void)sendImageWithURL:(NSURL *)imageURL {
NSString *imageName = [imageURL lastPathComponent];
[AdobeAssetFile create:imageName
folder:[AdobeAssetFolder root]
dataPath:imageURL
contentType:[AdobeAssetMimeTypes mimeTypeForExtension:#"jpg"]
collisionPolicy:AdobeAssetFileCollisionPolicyAppendUniqueNumber
progressBlock:^(double fractionCompleted) {
NSLog(#"Progress: %f", fractionCompleted);
}
successBlock:^(AdobeAssetFile *file) {
NSLog(#"Operation is complete");
}
cancellationBlock:^{
NSLog(#"Operation is canceled");
}
errorBlock:^(NSError *error){
NSLog(#"Error is occur: %#", error.localizedDescription);
}
];
}
What's wrong with this code? And why progressBlock not invocated?
I'm using Adobe Creative SDK v0.13.2139.
There is nothing wrong with your code. This is a known issue. A fix is in the works.

iOS using Facebook graph API for post without share dialog?

I want to use Facebook graph API to share on Facebook through my app, without presenting share dialog.But on reading various threads on internet i'm really confused about how to achieve this. i found this post on stack overflow but didn't able to find out how to make it works.
Can anyone give me step by step guideline or source code. any help would be highly appreciated.
Edit: code i used so far-
- (IBAction)StatusUpdateWithAPICalls:(id)sender {
[self openSessionForReadPermissions];
}
- (void)openSessionForReadPermissions
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
//this is called even from the reauthorizeWithPublishPermissions
if (state == FBSessionStateOpen && !error)
{
//[self openSessionForPublishPermissions];
//dispatch_async(dispatch_get_current_queue(), ^{
[self openSessionForPublishPermissions];
//});
}
else if (state == FBSessionStateClosedLoginFailed)
{
[FBSession.activeSession closeAndClearTokenInformation];
// [[NSNotificationCenter defaultCenter] postNotificationName:FBLoginErrorNotification object:session];
}
}];
}
-(void)openSessionForPublishPermissions
{
// We will post on behalf of the user, these are the permissions we need:
NSArray *permissionsNeeded = #[#"publish_actions"];
// Request the permissions the user currently has
[FBRequestConnection startWithGraphPath:#"/me/permissions"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error){
// Parse the list of existing permissions and extract them for easier use
NSMutableArray *currentPermissions = [[NSMutableArray alloc] init];
NSArray *returnedPermissions = (NSArray *)[result data];
for (NSDictionary *perm in returnedPermissions) {
if ([[perm objectForKey:#"status"] isEqualToString:#"granted"]) {
[currentPermissions addObject:[perm objectForKey:#"permission"]];
}
}
// Build the list of requested permissions by starting with the permissions
// needed and then removing any current permissions
NSMutableArray *requestPermissions = [[NSMutableArray alloc] initWithArray:permissionsNeeded copyItems:YES];
[requestPermissions removeObjectsInArray:currentPermissions];
NSLog(#"Asking: %#", requestPermissions);
// If we have permissions to request
if ([requestPermissions count] > 0){
// Ask for the missing permissions
[FBSession.activeSession requestNewPublishPermissions:requestPermissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// Permission granted, we can request the user information
[self makeRequestToUpdateStatus];
} else {
// An error occurred, handle the error
NSLog(#"%#", error.description);
}
}];
} else {
// Permissions are present, we can request the user information
[self makeRequestToUpdateStatus];
}
} else {
// There was an error requesting the permission information
// See our Handling Errors guide: https://developers.facebook.com/docs/ios/errors/
NSLog(#"%#", error.description);
}
}];
}
- (void)makeRequestToUpdateStatus {
// NOTE: pre-filling fields associated with Facebook posts,
// unless the user manually generated the content earlier in the workflow of your app,
// can be against the Platform policies: https://developers.facebook.com/policy
[FBRequestConnection startForPostStatusUpdate:#"User-generated status update."
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Status update posted successfully to Facebook
NSLog(#"result: %#", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#", error.description);
}
}];
}
but i getting this error-
Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. com.facebook.sdk:ErrorReauthorizeFailedReasonUserCancelled" UserInfo=0x78788e60 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:ErrorReauthorizeFailedReasonUserCancelled, NSLocalizedFailureReason=com.facebook.sdk:ErrorReauthorizeFailedReasonUserCancelled, com.facebook.sdk:ErrorSessionKey=<FBSession: 0x787ac750, state: FBSessionStateOpen, loginHandler: 0x787ac710, appID: 4201XXXXXXXXXXX, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x7a1c1b50>, expirationDate: 2015-04-20 06:48:00 +0000, refreshDate: 2015-02-19 09:39:47 +0000, attemptedRefreshDate: 0000-12-30 00:00:00 +0000, permissions:(
"public_profile"
)
And i'm not sure if i'm doing it right. please suggest me.
Use fallbacks.
Upload a photo via an app. FB logged in account

How to get Token using Twitter API 1.1 in iOS

I am using "STTwitter" for getting token from below URL and request body
https://dev.twitter.com/docs/api/1.1/post/oauth2/token
request body code with URL is below
- (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBlock errorBlock:(void(^)(NSError *error))errorBlock {
[self postResource:#"oauth2/token"
baseURLString:#"https://api.twitter.com"
parameters:#{ #"grant_type" : #"client_credentials" }
useBasicAuth:YES
uploadProgressBlock:nil
downloadProgressBlock:nil
successBlock:^(id request, NSDictionary *requestHeaders, NSDictionary *responseHeaders, id json) {
NSString *tokenType = [json valueForKey:#"token_type"];
if([tokenType isEqualToString:#"bearer"] == NO) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterAppOnlyCannotFindBearerTokenInResponse userInfo:#{NSLocalizedDescriptionKey : #"Cannot find bearer token in server response"}];
errorBlock(error);
return;
}
self.bearerToken = [json valueForKey:#"access_token"];
successBlock(_bearerToken);
} errorBlock:^(id request, NSDictionary *requestHeaders, NSDictionary *responseHeaders, NSError *error) {
errorBlock(error);
NSLog(#"ERROR %#",[error description]);
}];
}
For Calling above method i am doing below code
STTwitterAppOnly *twitter1 = [[STTwitterAppOnly alloc] init];
[twitter1 verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
NSLog(#"sd");
[self.twitter getUserTimelineWithScreenName:#"SEREEN_NAME"
successBlock:^(NSArray *statuses) {
NSLog(#"ERROR ::: %#",[statuses description]);
// ...
} errorBlock:^(NSError *error) {
// ...
}];
} errorBlock:^(NSError *error) {
// ...
}];
I got below Error when perform above code...
**Error Domain=STHTTPRequest Code=99 "Unable to verify your credentials"**
Can you suggest me what I missed in my code?
My concern is that, I want to read twitter feed without login in Twitter.Only using "Consumer Key" and "Secret Key" with Twitter API V1.1.
Thanks
if you have ConsumerKey and ConsumerSecret you can try it
STTwitterAPIWrapper *twitterAPI = [[STTwitterAPIWrapper twitterAPIApplicationOnlyWithConsumerKey:#"Your Consumer Key" consumerSecret:#"Your Consumer Secret"] autorelease];
[twitterAPI verifyCredentialsWithSuccessBlock:^(NSString *username) {
[twitterAPI getUserTimelineWithScreenName:#"your ScreenName" count:25 successBlock:^(NSArray *statuses) {
NSLog(#"Success:%#", statuses);
} errorBlock:^(NSError *error){
NSLog(#"Error : %#",error.description);
}];
} errorBlock:^(NSError *error) {
NSLog(#"Error : %#",error.description);
}];
Verify that you have enter Consumer key and Consumer Secret in both plist and header prefix...
The code you posted has several issues. First, you're making a request from the verify method error block instead of the success block. Second, you're using the postResource method directly, instead of the higher level one to do what you want.
If all that you want is a bearer token for your consumer tokens, you can just copy / paste the sample code from STTwitter README in the App Only Authentication section.

Posting a comment to a facebook post

I am using the newest facebook SDK 3.8 for iOS. I want to post a comment to a wall post and I am having troubles. The following method I am using works maybe once or twice and then gives me the error:
Error: The operation couldn’t be completed. (com.facebook.sdk error 5.)
I am not sure if it has to do with "overdoing" posting because I am only posting twice when this happens and on different posts each time. Like I said, it happens out of no where (Everytime before it is a success). So I believe it is my code. Can anyone tell me if I am doing this right?
Thank you!
-(BOOL) postComment: (NSString *) postID :(NSString *) userPostMessage;
{
__block BOOL value;
postID=[NSString stringWithFormat:#"/%#/comments?message=%#",postID,userPostMessage];
[FBSession activeSession];
[FBRequestConnection startWithGraphPath:postID parameters:0 HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
BOOL temp;
if (error)
{
NSLog(#"Error: %#", [error localizedDescription]);
temp = TRUE;
}
else
{
NSLog(#"Result: %#", result);
valueReturned = (NSString*)result;
temp = FALSE;
}
value = temp;
}];
return value;
}

Resources