Alternative to UIActivityViewController
Note: 2.0.2 — latest version with iOS5 support
The recommended way is to use CocoaPods package manager.
To install using CocoaPods open your Podfile and add:
pod 'GPActivityViewController', :git => 'https://github.com/gpinigin/GPActivityViewController.git'
For social networks listed below should be set application callback, for more info see chapter "Application callback".
// DO NOT forget to setup application IDs in info.plist. For more info see README.md
GPFacebookActivity *facebookActivity = [GPFacebookActivity new];
GPTwitterActivity *twitterActivity = [GPTwitterActivity new];
GPCopyActivity *copyActivity = [GPCopyActivity new];
GPMailActivity *mailActivity = [GPMailActivity new];
GPMessageActivity *messageActivity = [GPMessageActivity new];
GPOKActivity *okActivity = [GPOKActivity new];
GPVKActivity *vkActivity = [GPVKActivity new];
NSArray *activities = @[mailActivity, messageActivity, facebookActivity, twitterActivity,
vkActivity, okActivity, copyActivity];
GPActivityViewController *controller = [[GPActivityViewController alloc] initWithactivities:activities];
controller.userInfo = @{@"text":@"Message to pass to activities",
@"url":[NSURL URLWithString:@"https://github.com/gpinigin"]};
[controller presentFromBarButton:sender animated:YES];
To complete authentication you should register url-schemes and add application callbacks in application delegate:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// For iOS 5.X only
if ([FBSession.activeSession handleOpenURL:url]) {
return YES;
}
if ([[OdnoklassnikiMgr sharedInstance] handleOpenURL:url]) {
return YES;
}
if ([[VkontakteMgr sharedInstance] handleOpenURL:url]) {
return YES;
}
return NO;
}
// Call it when activity is finished
- (void)activityFinished:(BOOL)completed;
// Should returns string that unique identifies your activity
- (NSString *)activityType;
// Override to implement your activity behavior
- (void)performActivity;
Note for iOS5.0: if autoorientation behavior of your controller isn't match to one of GPActivityViewController you MUST subclass GPActivityViewController to override autorotation behavior or present controller modally
You also can make your custom activity using block approach:
GPActivity *myActivity = [customActivity:@"MACustomActivity" actionHandler:^(GPActivity *activity, NSDictionary *userInfo) {
// Your code here
// ...
// Activity is finished successfully
[activity activityFinished:YES];
}];
myActivity.image = [UIImage imageNamed:@"myCustom"];
myActivity.title = @"MyCustom";
You can also specify predefined acitivityInfo:
NSURL *url = [NSURL URLWithString:@"google.com"];
activity.userInfo = @{@"text":@"My custom activity",
@"url":url};
Partially based on REActivityViewController
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。