如何在IOS 9中检查联系社交帐户

时间:2015-10-24 11:47:29

标签: ios swift ios9

如果您想设置社交帐户,我知道您可以这样做:

let facebookProfile = CNLabeledValue(label: "Facebook", value: CNSocialProfile(urlString: "https://www.facebook.com/appsfoundation", username: "AppsFoundation", userIdentifier: "appsfoundation", service: CNSocialProfileServiceFacebook))

let twitterProfile = CNLabeledValue(label: "Twitter", value: CNSocialProfile(urlString: "https://twitter.com/AppsFoundation", username: "AppsFoundation", userIdentifier: "appsfoundation", service: CNSocialProfileServiceTwitter))

newContact.socialProfiles = [facebookProfile, twitterProfile]

但是,您如何实际检查联系人是否有任何社交个人资料以及如何检索他们?

2 个答案:

答案 0 :(得分:1)

您似乎必须使用value属性:

for i in 0..<contact.socialProfiles.count {
    if (contact.socialProfiles[i].value as! CNSocialProfile).service == CNSocialProfileServiceFacebook {
    facebookAccount.text = (contact.socialProfiles[i].value as! CNSocialProfile).username

    } else {
       facebookAccount.text = ""
    }

    if (contact.socialProfiles[i].value as! CNSocialProfile).service == CNSocialProfileServiceTwitter {
    twitterAccount.text = (contact.socialProfiles[i].value as! CNSocialProfile).username
    } else {
       twitterAccount.text = ""
    }
}

答案 1 :(得分:-1)

//这将获取不同帐户(如twitter,facebook等)的所有值os SocialProfile

for (CNLabeledValue<CNSocialProfile*>* labeledValue in contact.socialProfiles)
{

      NSString * socialProfileurlString = labeledValue.value.urlString;
      NSLog(@"socialProfileurlString = %@",socialProfileurlString);

      NSString *socialProfileUsername = labeledValue.value.username;
      NSLog(@"socialProfileUsername = %@",socialProfileUsername);

      NSString *socialProfileUserIdentifier = labeledValue.value.userIdentifier;
      NSLog(@"socialProfileUserIdentifier = %@",socialProfileUserIdentifier);

      NSString *socialProfileUserService = labeledValue.value.service;
      NSLog(@"socialProfileUserService = %@",socialProfileUserService);

}