ios - Is it possible to include different content for different social media using UIActivityViewController? -
i using mobilecoreservices of ios 7 post content app social media. . , here code ..
nsarray *activityitems; nsstring *title = _titlelabel.text; if (_imagelabel.image != nil) { activityitems = @[title, _imagelabel.image]; } else { activityitems = @[title]; } uiactivityviewcontroller *activitycontroller = [[uiactivityviewcontroller alloc] initwithactivityitems:activityitems applicationactivities:nil]; [self presentviewcontroller:activitycontroller animated:yes completion:nil];
now sends common text. wish post different titles facebook , twitter. possible?
i found tutorial helpful: http://www.albertopasca.it/whiletrue/2012/10/objective-c-custom-uiactivityviewcontroller-icons-text/
but gist of following:
you need subclass uiactivityitemprovider
@interface apcustomactivityprovider : uiactivityitemprovider <uiactivityitemsource> @end
add following implementation file
@implementation apcustomactivityprovider - (id) activityviewcontroller:(uiactivityviewcontroller *)activityviewcontroller itemforactivitytype:(nsstring *)activitytype { if ( [activitytype isequaltostring:uiactivitytypeposttotwitter] ){ nsstring *title = @"twitter title"; return title; } if ( [activitytype isequaltostring:uiactivitytypeposttofacebook] ) { nsstring *title = @"facebook title"; return title; } return nil; } - (id) activityviewcontrollerplaceholderitem:(uiactivityviewcontroller*)activityviewcontroller { return @""; } @end
to use custom activityprovider, go presenting uiactivityviewcontroller
nsarray *activityitems; apcustomactivityprovider *activityprovider = [[apcustomactivityprovider alloc] init]; if (_imagelabel.image != nil) { activityitems = @[activityprovider, _imagelabel.image]; } else { activityitems = @[activityprovider]; } uiactivityviewcontroller *activitycontroller = [[uiactivityviewcontroller alloc] initwithactivityitems:activityitems applicationactivities:nil]; [self presentviewcontroller:activitycontroller animated:yes completion:nil];
Comments
Post a Comment