Facebook和Twitter不支持UIActivityViewController,仍然在這個只使用有限的應用程序。現在這個代碼非常有用。
- (無效)uploadImageToTwitter {
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil
completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
NSArray *arrayOfAccounts = [account
accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
ACAccount *twitterAccount =
[arrayOfAccounts lastObject];
//
// NSURL *捲起= [NSURL fileURLWithPath:NSTemporaryDirectory()]; // NSURL * fileURL = [furl URLByAppendingPathComponent:@「animation.gif」];
NSData *imageData = [NSData dataWithContentsOfURL:_GIFURL];
NSURL *requestURL = [NSURL URLWithString:@"https://upload.twitter.com/1.1/media/upload.json"];
SLRequest *postRequest = [SLRequest
requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:requestURL parameters:nil];
postRequest.account = twitterAccount;
[postRequest addMultipartData:imageData
withName:@"media"
type:@"image/gif"
filename:@"test.gif"];
[postRequest
performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
NSString *mediaID = [json objectForKey:@"media_id_string"];
if (mediaID!=nil) {
NSURL *requestURL2 = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"];
NSDictionary *message2 = @{@"status": @"Here is the image",
@"media_ids": mediaID };
SLRequest *postRequest2 = [SLRequest
requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:requestURL2 parameters:message2];
postRequest2.account = twitterAccount;
[postRequest2
performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
// DONE!!!
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Notification" message:@"Upload Twitter Account" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}];
}
}];
}
}
}];
}
'UIDocumentInteractionController'。 – rmaddy 2014-10-16 22:25:23
分享什麼?一個文件需要一個應用程序才能運行。命名一個。 – 2014-10-17 04:14:22
請參閱我習慣了Android,我只是想調用一個共享文件的意圖,然後彈出一個Gmail,Facebook,Twitter等等的列表......如果可能的話,我基本上都希望獲得相同的結果。 – FTLRalph 2014-10-17 11:38:35