ShareKit 2.0 facebook share URL - ios

I have the following code for sharing with facebook using ShareKit:
-(void)buttonAction:(id)sender
{
[SHK setRootViewController:self];
SHKItem *facebookItem = [[SHKItem alloc] init];
facebookItem = [SHKItem URL:[NSURL URLWithString:#"www.google.com"] title:#"Some test title"];
facebookItem.facebookURLSharePictureURI = #"www.myTestPicture.com";
facebookItem.facebookURLShareDescription = #"Custom share description";
[SHKFacebook shareItem:facebookItem];
}
Everything works fine except for one scenario. My application has a log out button. Upon hitting this button, all the data save in NSUserDefaults gets erased. So, I log in and then make a post to facebook. Then, I log out (erase all the data) and afterwards log back in with facebook. Everything works so far. However if I try to make another post to facebook at this point, my application crashes with no error showing up in the console. If I restart the application and try to make the same post again, it works. It only crashed after loging out, back in (with facebook) and then trying to make the post. Any clues? Thanks.
EDIT: Seems like it is crashing in FBDialog at line 341:
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(kPadding, kPadding, 480, 480)];

Ok, so after some digging aroung here, it seems to be Apple's bug in iOS 5.1 according to Why does clearing NSUserDefaults cause EXC_CRASH later when creating a UIWebView?

Related

iOS Document Sharing: "Save to Dropbox" always fails

Posting after finding answer
After "rubber duck debugging" this answer a bunch, I finally came across the correct answer on a question that appears to me to be unrelated. I think this question (and its answer) are still relevant, so I'm posting the question and will post my own answer to hopefully help others like me.
I am creating a PDF in my iOS app that I would like to allow the user to export. For the purposes of this testing, I'm trying to save it to my personal Dropbox on a physical device.
I have turned on iTunes file sharing, and I can verify that the PDF file is being generated correctly, and when I copy it off of my device (iPad Pro Gen. 2 running iOS 11), I can open the PDF and it has the expected content and appearance.
I am able to get the document pop-up to display correctly, and I have options to share via:
Line 1: AirDrop
Line 2: Message, Mail, Add to Notes, (Facebook) Messenger, etc.
Line 3: Copy, Print, Save to Files, Save to Dropbox, etc.
No matter what I try to select (Save to Dropbox is the one I want to solve, but the issue seems universal), it fails. Of note, when I click Save to Dropbox, I do see the Dropbox panel display, but there is immediately a modal over top of the Save to Dropbox modal that says, "An unknown error occurred."
I have tried to look around and see how to get more information about this error, but I'm stumped. I'm not sure if it's correlated, but I get this message in the console:
[AXRun-PID] Client requesting unsuspension of PID:813 Name:<redacted>
Trying to google that error has proved unfruitful.
Here's the code where I generate the PDF and show the menu:
#pragma mark • Sharing Methods
- (void)showShareMenu {
NSArray *bookList = [BookManager bookList];
NSURL *pdfUrl = [PdfGenerator generatePdfFromBooks:bookList];
UIDocumentInteractionController *vc = [[UIDocumentInteractionController alloc] init];
vc.name = #"Booklet.pdf";
vc.URL = pdfUrl;
vc.UTI = #"com.adobe.pdf";
[vc presentOptionsMenuFromBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];
}
I've tried using UIDocumentInteractionController *vc = [UIDocumentInteractionController interactionControllerWithURL:pdfUrl]; instead of the one above, but the results are the same.
I tried making self the delegate of vc and then tried to implement the following methods:
- (void)documentInteractionController:(UIDocumentInteractionController *)controller
willBeginSendingToApplication:(nullable NSString *)application;
- (void)documentInteractionController:(UIDocumentInteractionController *)controller
didEndSendingToApplication:(nullable NSString *)application;
Neither of those methods ever fired.
Interestingly, though I think I've supplied the file name correctly based on what I've read, the name in the File textbook in the Save to Dropbox modal is a current timestamp (e.g., File Oct 28, 11 12 22 PM). The Dropbox modal stays up until I click "OK" on the "An unknown error occurred" modal, and then disappears immediately.
It seems like I'm somehow not providing the right information, but I'm not sure how. It seems like there ought to be a delegate method to indicate an error to me, but I don't see anything like that in the docs. (It is late, and I have been looking at this for hours, including reading several related tutorials, so I could have missed something obvious.)
I came across this answer as an example question while asking this current question.
It doesn't really ask the same question I have, nor did that user have the same error outputs I did. But, the linked answer did work for me, too.
The problem I had in the code above was that I was not keeping the UIDocumentInteractionController around after I created it. Adding a private property fixed this issue. So, the following code now works:
#pragma mark • Sharing Methods
- (void)showShareMenu {
NSArray *bookList = [BookManager bookList];
NSURL *pdfUrl = [PdfGenerator generatePdfFromBooks:bookList];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:pdfUrl];
self.docController.name = #"Booklet.pdf";
self.docController.UTI = #"com.adobe.pdf";
[self.docController presentOptionsMenuFromBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];
}

Spotify SPTAuthViewController issues

I am having trouble authorizing Spotify. The first time I believe I logged in but it froze up on the last page of the authentication process. Now when I try to log in, the popover is a blank screen. Also when I clear my cookies, the login screen appears but won't proceed past me entering my username and password. I appreciate the help here
I have tried doing this in both objective c as per the "Simple Track Playback" demo in the sdk and in swift using this tutorial http://pachulski.me/2015/spotifyframework-with-swift/
I was running into the same issue (blank popover). This was fixed when I added "App Transport Security Settings" (type: Dictionary) into the info.plist, and then implementing "Allow Arbitrary Loads" (Type: BOOL) and setting it to "YES".
Please refer to the screenshot:
EDIT: Added code to answer Brian's question in comments:
- (IBAction)loginButtonPressed:(id)sender {
_authVC = [SPTAuthViewController authenticationViewController];
_authVC.delegate = self;
_authVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
_authVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.definesPresentationContext = YES;
[self presentViewController:_authVC animated:NO completion:nil];
}

Xcode - Admob banner setting with targeting and test devices

I am working on my iOS app and trying to place a banner on the bottom of the page.
First of all, I set a BOOL (BannerAd) which is initially "NO" and set to "YES" when user hits the "Submit" button. By doing this tried to avoid requesting ads eveytime the user hit "Submit". This seems to work but world be nice if you can comment on it.
My interface has a "Datepicker" where the user selects his/her Birthday. I wanted to use this information for ad targeting. Also I know my application will be used in "Germany" so I set the location manually to "Germany" since my app doesn't request location information from user. And finally I am trying to test my app on my device where I set my test device UDID in "testDevices"
My problem is, I think my requests don't work. When I enter my own "adUnitId", I get paid ads on my device (which may cause a problem). Also when I tried to change the location, for example to "France", I still get local ads. I guess my location is not working and AdMob is using the network to determine the location. Which makes me think my "Birthday" information isn't working, too.
Below is the code I use and I don't know which part is wrong. I did researched and did everything according to the guides. I am not experienced and hoped that you guys can help me out!
Appreciated!
// Show Banner Ad
if (BannerAd == NO)
{
self.bannerView.adUnitID = #"ca-app-pub-3940256099942544/2934735716"; // TEST ID
self.bannerView.rootViewController = self;
NSDate *birthday =[datepick date];
GADRequest *request = [GADRequest request];
[request setBirthday: birthday];
[request setLocationWithDescription:#"Germany"];
request.testDevices = #[ #"b23cbd41317324cd9afd14dc848f2f0e" // TEST DEVICE
];
[self.bannerView loadRequest:[GADRequest request]];
BannerAd = YES;}
I can't understand your question(s) so good. Sorry.
If you want to put your adMob banner on the bottom of the screen, just use:
bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,self.view.frame.size.height - 50, self.view.frame.size.width, CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).height)];

UIDocumentInteractionController presentOptionsMenuFromBarButtonItem error in ios8- Unknown activity items supplied

UIDocumentInteractionController presentOptionsMenuFromBarButtonItem gives me a console error in ios8 hardware (and not on 7.1 hardware or earlier):
Unknown activity items supplied: (
{
"com.adobe.pdf" = ;
},
""
)
In my official App Store version of my app, the app crashes at this point. When I compile and run on my iPad it just gives the error but does not crash.
My code:
In the .h:
UIDocumentInteractionController *docInteractionController;
In the .m:
self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
self.docInteractionController.delegate = self;
//UIBarButtonItem *element is an element in my toolbar
[self.docInteractionController presentOptionsMenuFromBarButtonItem:element animated:YES];
If I do a NSLog of docInteractionController.UTI I see "com.adobe.pdf" at the console, so the UTI is being recognized properly.
I can get around the "Unknown activity items" by using presentOpenInMenuFromBarButtonItem instead of presentOptionsMenuFromBarButtonItem for the UIDocumentInteractionController call, but I want to show the user the print and email options as well, not only the external app opening options.
Tested on iPad version 8.0.2. Xcode version 6.0.1, deployment target 6.0 (also tested with deployment target 8.0). All objective-c. Running on iPad version 7.1 does not produce the error.
See radar: http://openradar.appspot.com/radar?id=5800473659441152
As noted you can use presentOpenInMenu instead of presentOptionsMenu. You will loose the mail option but you can do it yourself with MFMailComposeViewController with a dedicated mail button.
Or use UIActivityViewController with an "Open In" activity item.
Or just a UIActivityViewController without an "Open In" activity item if that is enough
Or do presentOptionsMenu on iOS7 runtime and UIActivityViewController on iOS8+ runtime (where share extensions exist)
For people not wanting to use UIActivityViewController because the document controller is what we want (all actions show up): you can get around the crash by retaining the UIDocumentInteractionController, e.g. by assigning it to a property and releasing when the document interaction finishes:
- (void)share:(id)sender
{
self.documentInteraction = [UIDocumentInteractionController interactionControllerWithURL:_shareURL];
_documentInteraction.delegate = self;
_documentInteraction.name = self.title;
[_documentInteraction presentOptionsMenuFromBarButtonItem:_actionItem animated:YES];
}
- (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
{
if (controller == _documentInteraction) {
self.documentInteraction = nil;
}
}
The log will still show up, at least in debug, haven't checked with a release build. But it all works.
This solved the problem for me:
dispatch_async(dispatch_get_main_queue(), ^() {
[_docController presentOptionsMenuFromRect:button.bounds inView:button animated:YES];
});
I was getting the same console logs, but only in debug builds. Try creating a release build and you should see it still prints the "Unknown activity items supplied" error, but without the entire contents of the file.

facebook ios sdk log : strange message

I've got a button to share an image and every times I click it, I've got this message in the log, I dont understand :
2012-08-12 19:21:30.511 AvisOcean[2239:707] An instance 0xe6b8fe0 of class FBSessionManualTokenCachingStrategy was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
(
Context: 0xa5e90, Property: 0x245310>
Context: 0xa5e90, Property: 0x28c400>
)
Any ideas?
The Facebook SDK is leaking observers. I am using SDK v3.1.
This shouldn't be an issue if you are using the SDK without the deprecated headers (ie Facebook.h). But to use native dialogs you need to include the deprecated headers (source: https://developers.facebook.com/docs/howtos/feed-dialog-using-ios-sdk/) which leads to this error when closing/cleaning the active session.
Here is a pull request to fix it: https://github.com/facebook/facebook-ios-sdk/pull/474
You can then rebuild the SDK using Facebook SDK for iOS6/Xcode 4.5 not working
I was having the same problem. I think what had happend is I had initialized Facebook else where and it was giving me errors when I tried to re-initialize it and again invoke a dialog delegate from a different instance.
The instance where i was keeping actual app initialization and accesstoken were different from the one which was invoking the dialog. When I corrected that after going over the documentation, it was solved.
if (nil == self.facebook) {
self.facebook = [[Facebook alloc]
initWithAppId:FBSession.activeSession.appID
andDelegate:nil];
// Store the Facebook session information
self.facebook.accessToken = FBSession.activeSession.accessToken;
self.facebook.expirationDate = FBSession.activeSession.expirationDate;
}
[self.facebook dialog:#"feed" andParams:params andDelegate:self];
Do a quick logout prior to assigning accessToken and expirationDate, that will help clean up some nasty error that you had seen. I'm sure this is just a temporary solution for those using deprecated Facebook headers.
// Initiate a Facebook instance
if(!_facebook)
_facebook = [[Facebook alloc] initWithAppId:FBSession.activeSession.appID andDelegate:nil];
// Store the Facebook session information
[_facebook logout];
_facebook.accessToken = FBSession.activeSession.accessToken;
_facebook.expirationDate = FBSession.activeSession.expirationDate;
I see this message when my Facebook object is dealloc'ed. I'm using the 3.0.8 SDK. In my case I'm thinking that the Facebook object should remove itself as an observer of its tokenCaching before releasing it in its dealloc. Your case might be different since it doesn't sound like you'd be clearing the FB object. Perhaps the suggestions here would help.

Resources