Google Consent SDK: How to Save 'Status' Array in UserDefaults? - ios

The variable "status" is not used in this code. Therefore I cannot check the user's consent choice.
I have to store 'status array' in defaults. Once current status is available in array it will not show that Consent form. If not then we will show form and add that status in defaults status array.
Now I cannot check user's consent choice, and the form will load every time on app load.
This would probably solve the problem, but I do not know how to do that in code. Any suggestions?
// Load Form
[form loadWithCompletionHandler:^(NSError *_Nullable error) {
NSLog(#"Load complete. Error: %#", error);
if (error) {
// Handle error.
} else {
// Load successful.
[form presentFromViewController:self
dismissCompletion:^(NSError *_Nullable error, BOOL userPrefersAdFree) {
if (error) {
// Handle error.
} else if (userPrefersAdFree) {
// The user prefers to use a paid version of the app.
} else {
// Check the user's consent choice.
PACConsentStatus status =
PACConsentInformation.sharedInstance.consentStatus;
// store status array in defaults
// once current status is available in array we will not show that form
// if not then we will show form and add that status in defaults status array
//Storing publisher managed consent
PACConsentInformation.sharedInstance.consentStatus = PACConsentStatusPersonalized;
}
}];

I have little clue of iOS, but I'd guess you just have to write the assignment into a single line:
PACConsentStatus status = PACConsentInformation.sharedInstance.consentStatus;

Related

use of restorePreviousSignIn() in googleSign in iOS

Google migration doc here says that
// Old:
guard let signIn = GIDSignIn.sharedInstance() else { return }
if (signIn.hasAuthInKeychain()) {
signIn.signInSilently()
}
// New:
guard let signIn = GIDSignIn.sharedInstance() else { return }
if (signIn.hasPreviousSignIn()) {
signIn.restorePreviousSignIn()
// If you ever changed the client ID you use for Google Sign-in, or
// requested a different set of scopes, then also confirm that they
// have the values you expect before proceeding.
if (signIn.currentUser.authentication.clientID != YOUR_CLIENT_ID
// TODO: Implement hasYourRequiredScopes
|| !hasYourRequiredScopes(signIn.currentUser.grantedScopes)) {
signIn.signOut()
}
}
As I had tried with device user still get redirect to account.google.com and have to choose the account right? so what is use of restorePreviousSignIn(). How it benefit to user? Thanks in advance.
Do you set the GIDSignInDelegate (GIDSignIn.sharedInstance().delegate) before calling restorePreviousSignIn()?
As the documentation of restorePreviousSignIn() says:
The delegate will be called at the end of this process indicating success or failure. The current values of GIDSignIn's configuration properties will not impact the restored user.
Btw. I'm using the restorePreviousSignIn() without any trouble.
// Sorry for asking in answer, I don't have enough reputation to comment on you question.

The app with id xxxxxxxx does not have the right view_structure on app with id yyyy

I'm trying to create a new item in a podio app in an iOS app with. The following lines of code as per the documentation in podio but I am having a 403 error with the subject as the error message. I assumed that I needed to authenticate the session as an app as I think that it will use the app id to create the PKTItem in the app used to sign in.
let item = PKTItem(forAppWithID: lastItem + 1)
item?.setValue(1, forField: "service")
item?.setValue(testPet, forField: "pet")
item?.save().onComplete({(response, error) in
if (error != nil){
print("error: \(error)")
}
else{
print("response")
}
})
I was in the assumption that the item would be created in the app that was used to sign with the item having an id of lastItem + 1, I tried to see if the object's IDs are correct
//this is supposed to be lastItem + 1
print("PKTItem ID: \(item?.appItemID)")
//this is supposed to be the app ID where it should create the new item
print("PKTItem AppID: \(item?.appID)")
PKTItem ID: Optional(0)
PKTItem AppID: Optional(1)
I don't what I was doing wrong. Please assist me.
Sounds like you are using the wrong set of credentials to look at the app item you are attempting to work with. How did you authorize? Do you have the right App ID and Token combination for this script?
Typically you will see [PodioKit authenticateAutomaticallyAsAppWithID:123456 token:#"my-app-token"]; and that allows you to interact with anything in the the app 123456, but it sounds like you are trying to interact with data in 2 apps based on the error message. If this is a small scale implementation (or for testing purposes) you can use the Authenticate as User method instead. Here is the documentation they have on Authentication for the Objective C library.
PKTAsyncTask *authTask = [PodioKit authenticateAsUserWithEmail:#"myname#mydomain.com" password:#"p4$$w0rD"];
[authTask onComplete:^(PKTResponse *response, NSError *error) {
if (!error) {
// Successfully authenticated
} else {
// Failed to authenticate, double check your credentials
}
}];

How to know user is online or offline in quickblox for iOS?

I am storing user contact in arrContactList
NSArray *arrContactList = [QBChat instance].contactList.contacts;
From arrContactList, how the presence status can be derived.
Also after getting presence status, if user goes online or offline, how it can be found.
// contact has userId and presence status
for(QBContactListItem *contact in arrContactList) {
BOOL isOnline = contact.isOnline;
NSInteger userIdValue = contact.userID;
if(isOnline) {
NSLog(#"User %ld is online",(long)userIdValue);
}
else {
NSLog(#"User %ld is offline",(long)userIdValue);
}
}
// When a contact user goes online or offline, this method gets called
- (void)chatDidReceiveContactItemActivity:(NSUInteger)userID isOnline:(BOOL)isOnline status:(NSString *)status{
// here you can check presence status using isOnline and also we get userID
// so list of user IDs who are online can be maintained in an array
}

SoundCloud API iOS Fails to upload audio with a HTTP 422 error

I'm trying to put a super basic Soundcloud feature in my app to upload single .wav files using their UI. I followed their guide and I didn't really need anything outside of the bare bones share menu so I assumed this code would work:
NSURL *trackURL = [[NSURL alloc] initWithString:[docsDir stringByAppendingPathComponent:fileToShare]];
SCShareViewController *shareViewController;
shareViewController = [SCShareViewController shareViewControllerWithFileURL:trackURL
completionHandler:^(NSDictionary *trackInfo, NSError *error){
if (SC_CANCELED(error)) {
NSLog(#"Canceled!");
} else if (error) {
NSLog(#"Ooops, something went wrong: %#", [error localizedDescription
]);
} else {
// If you want to do something with the uploaded
// track this is the right place for that.
NSLog(#"Uploaded track: %#", trackInfo);
}
}];
// If your app is a registered foursquare app, you can set the client id and secret.
// The user will then see a place picker where a location can be selected.
// If you don't set them, the user sees a plain plain text filed for the place.
[shareViewController setFoursquareClientID:#"<foursquare client id>"
clientSecret:#"<foursquare client secret>"];
// We can preset the title ...
[shareViewController setTitle:#"Funny sounds"];
// ... and other options like the private flag.
[shareViewController setPrivate:NO];
// Now present the share view controller.
[self presentModalViewController:shareViewController animated:YES];
[trackURL release];
However I get an HTTP 422 error with this appearing in my debug console:
2016-02-29 11:04:47.129 synthQ[801:443840] parameters: {
"track[asset_data]" = "/var/mobile/Containers/Data/Application/EE58E5CA-B30C-44EB-B207-EB3368263319/Documents/bb.wav";
"track[downloadable]" = 1;
"track[post_to][]" = "";
"track[sharing]" = public;
"track[tag_list]" = "\"soundcloud:source=synthQ\"";
"track[title]" = "Funny sounds";
"track[track_type]" = recording;
}
2016-02-29 11:04:47.164 synthQ[801:444011] -[NXOAuth2PostBodyStream open] Stream has been reopened after close
2016-02-29 11:04:47.373 synthQ[801:443840] Upload failed with error: HTTP Error: 422 Error Domain=NXOAuth2HTTPErrorDomain Code=422 "HTTP Error: 422" UserInfo={NSLocalizedDescription=HTTP Error: 422}
Does anyone have any ideas what could be going wrong here?
Thanks!
One of the reason to get HTTP 422 error in SoundCloud is:
If you are trying to upload a file for a first time with a new account, you need to verify your email address to complete your SoundCloud registration in order to upload your files.
There might be other reasons for this error, however for my case it was the case and that solved the problem.
You cannot reference external resources while uploading tracks. You
therefor need to download the track to your computer and then perform
the actual upload to SoundCloud.
Source
Soundcloud file uploading issue HTTP 442
I managed to solve this by using a different constructor that passes the audio file as an NSData object:
shareViewController = [SCShareViewController shareViewControllerWithFileData:[NSData dataWithContentsOfFile:[docsDir stringByAppendingPathComponent:fileToShare]]
completionHandler:^(NSDictionary *trackInfo, NSError *error){
if (SC_CANCELED(error)) {
NSLog(#"Canceled!");
} else if (error) {
NSLog(#"Ooops, something went wrong: %#", [error localizedDescription
]);
} else {
// If you want to do something with the uploaded
// track this is the right place for that.
NSLog(#"Uploaded track: %#", trackInfo);
}
}];

Parse.com saving non logged in users

I am building an iOS app with a following/follower relation using Parse.com. I am trying to do something where every time a user follows another user it puts the follower into to an array of Followers in Parse.com but i can not save a user who is not logged in. Is there anyway to get around this using the iOS SDK?
If you want to save a user that is not the current user, you will have to use cloud code and the master key. You can send up the id of the user you want to change, query for that user, and change any fields you want. Here is my cloud code function for editing users, where "myUser" is the id I sent up:
Parse.Cloud.define("editUser", function(request, response) {
//var GameScore = Parse.Object.extend("SchoolHappening");
// Create a new instance of that class.
//var gameScore = new GameScore();
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.get(request.params.myUser, {
success: function(myUser) {
// The object was retrieved successfully.
myUser.set("cabinetPosition", request.params.myPosition);
// Save the user.
myUser.save(null, {
success: function(myUser) {
// The user was saved successfully.
response.success("Successfully updated user.");
},
error: function(gameScore, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
response.error("Could not save changes to user.");
}
});
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
}
});
});
You can learn more about cloud code in the parse docs.
You can try to set an array property in your follower user (logged in) which represents the id of users he actually follows. Each time you follows another user, add his objectId in the array.
To get all your followers, use whereKey:containsAllObjectsInArray: method of PFQuery
PFQuery *followersQuery = [PFUser query];
[followersQuery whereKey:#"followsId" containsAllObjectsInArray:#[[PFUser currentUser].objectId]];
[followersQuery findObjectsInBackgroundWithBlock:^(NSArray *followersArray, NSError *error){
// Do stg
}];

Resources