Unless FBSession can respond to its own delegate, no. Also, I think at the time you set the delegate, the pointer for FBSession is nothing. No, it wouldn't work.
Hey I have another weird problem with ShareKit leaks here:
Whenever I clearly release something, analyzer complains that there is a leak even though there is not. I am using Beta 5 of the iOS SDK so I don't think its a bug.
I have gotten it down to 6 (Edit: Now 5) leaks/minor analyzer problems left that are a bit different from the others:
(Bold line is where I alloc it)
1.
Code:
+ (void)flushOfflineQueue
{
// TODO - if an item fails, after all items are shared, it should present a summary view and allow them to see which items failed/succeeded
// Check for a connection
if (![self connected])
return;
// Open list
NSMutableArray *queueList = [self getOfflineQueueList];
// Run through each item in the quietly in the background
// TODO - Is this the best behavior? Instead, should the user confirm sending these again? Maybe only if it has been X days since they were saved?
// - want to avoid a user being suprised by a post to Twitter if that happens long after they forgot they even shared it.
if (queueList != nil)
{
SHK *helper = [self currentHelper];
if (helper.offlineQueue == nil)
helper.offlineQueue = [[NSOperationQueue alloc] init];
SHKItem *item;
NSString *sharerId, *uid;
for (NSDictionary *entry in queueList)
{
item = [SHKItem itemFromDictionary:[entry objectForKey:@"item"]];
sharerId = [entry objectForKey:@"sharer"];
uid = [entry objectForKey:@"uid"];
if (item != nil && sharerId != nil)
[helper.offlineQueue addOperation:[[[SHKOfflineSharer alloc] initWithItem:item forSharer:sharerId uid:uid] autorelease]];
}
// Remove offline queue - TODO: only do this if everything was successful?
[[NSFileManager defaultManager] removeItemAtPath:[self offlineQueueListPath] error:nil];
}
}
[FIXED] 2.
Code:
- (void)share
{
// create sharer
SHKSharer *tempsharer = [[NSClassFromString(sharerId) alloc] init];
self.sharer = tempsharer;
sharer.item = item;
sharer.quiet = YES;
sharer.shareDelegate = self;
if (![sharer isAuthorized])
{
[self finish];
return;
}
// reload image from disk and remove the file
NSString *path;
if (item.shareType == SHKShareTypeImage)
{
path = [[SHK offlineQueuePath] stringByAppendingPathComponent:uid];
sharer.item.image = [UIImage imageWithContentsOfFile:path];
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}
// reload file from disk and remove the file
else if (item.shareType == SHKShareTypeFile)
{
path = [[SHK offlineQueueListPath] stringByAppendingPathComponent:uid];
sharer.item.data = [NSData dataWithContentsOfFile:[[SHK offlineQueuePath] stringByAppendingPathComponent:uid]];
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}
[sharer tryToSend];
[tempsharer release];
}
I tried it this way like I did for my other problems but no luck.
3.
Code:
/* Wipe variables */
a = b = c = d = e = 0;
That is not a leak but a value stored to 'a' is never read.
I updated my post above, also don't worry about #5, I fixed that. Also how about 6? Also I am not sure how to fix #1 because it is not a self.whatever, it is a helper.whatever so what would I do in that case? Also, I updated #2's code with the way that should fix it but it stills complains about a leak
Thanks, that fixed it. Now what about #1,#2,#3, and #6. I thought that just by deleting #3 code line would fix the analyzer warning wouldn't it? And for #1, and #2, I tried your suggestion but I edited my long code post on why/how it didn't work.
For 2 you shouldn't be releasing sharer in that method - you really need to read up on properties. BrianSlick has a good post on them.
I updated that code taking out [sharer release]; but it still throws up a analyzer warning in that bolded line. In the meantime I will look over BrianSlick's properties guide but this one just baffles me on why it should be showing a warning whatsoever.