This question already has answers here:
WatchKit Option to ONLY Dictate?
(2 answers)
Closed 7 years ago.
According to Apple's doc of WKInterfaceController you can let user to dictate text preseting a new interface controller in this very simple way:
self.presentTextInputControllerWithSuggestions(["suggestion 1", "suggestion 2"] allowedInputMode: .Plain, completion: { (answers) -> Void in
if reply && reply.count > 0 {
if let answer = answers[0] as? String {
println("\answer")
}
}
})
as explained here.
I have seen that Amazon App for Apple Watch let you search for products by tapping the search icon directly
So you get into the Dictation in one step
Through the WKInterfaceController method, we will get something different
Which Apple's API Amazon app is using to enable dictation in this way?
(UPDATE)
I have just find out that it's super easy as explained here
So the final solution I came out was this
- (void) table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {
if (rowIndex==0) { // handle manual selection
__weak MainInterfaceController *weakSelf = self;
[self presentTextInputControllerWithSuggestions:nil allowedInputMode:WKTextInputModePlain completion:^(NSArray *results) {
if(results && [results count]>0) {
NSString *inputText=nil;
for(NSString *input in results) {
NSLog(#"Input %#", input);
inputText=input;
break;
}
if(inputText!=nil && [inputText length]>0) {
[weakSelf pushControllerWithName:#"Search" context:
[NSDictionary dictionaryWithObjectsAndKeys:
inputText, #"query", nil]
];
}
} else {
NSLog(#"No input provided");
}
}];
}}
Set the mode to .Plain and don't provide any suggestions.
If you remove the suggested strings array, it will go straight into dictation mode.
Related
I've done as the guide says
This is the message manager
[GNSMessageManager setDebugLoggingEnabled:YES];
messageManager = [[GNSMessageManager alloc] initWithAPIKey:API_KEY paramsBlock:^(GNSMessageManagerParams *params) {
params.bluetoothPowerErrorHandler = ^(BOOL hasError) {
// Update the UI for Bluetooth power
};
params.bluetoothPermissionErrorHandler = ^(BOOL hasError) {
// Update the UI for Bluetooth permission
};
}];
These are my methods to publish and subscribe with the Nearby API.
- (IBAction)onPublish:(id)sender {
NSLog(#"publish");
NSString* str = #"hello world";
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
GNSMessage* message = [GNSMessage messageWithContent:data];
id<GNSPublication> publication = [messageManager publicationWithMessage:message paramsBlock:^(GNSPublicationParams *publicationParams) {
publicationParams.strategy = [GNSStrategy strategyWithParamsBlock:^(GNSStrategyParams * strategyParams) {
strategyParams.allowInBackground = YES;
strategyParams.discoveryMediums = kGNSDiscoveryMediumsBLE;
strategyParams.discoveryMode = kGNSDiscoveryModeDefault;
}];;
}];
}
- (IBAction)onSubscribe:(id)sender {
NSLog(#"subscribe");
id<GNSSubscription> subscription = [messageManager subscriptionWithMessageFoundHandler:^(GNSMessage *msg) {
// Add the name to a list for display
NSLog(#"message found %#", [msg description]);
} messageLostHandler:^(GNSMessage *msg) {
// Add the name to a list for display
NSLog(#"message lost %#", [msg description]);
} paramsBlock:^(GNSSubscriptionParams *subscriptionParams) {
subscriptionParams.strategy = [GNSStrategy strategyWithParamsBlock:^(GNSStrategyParams * strategyParams) {
strategyParams.allowInBackground = YES;
strategyParams.discoveryMediums = kGNSDiscoveryMediumsBLE;
strategyParams.discoveryMode = kGNSDiscoveryModeDefault;
}];;
}];
}
Both Bletooth central and peripheral background capabilities are enabled, and the permission string for the peripheral is set.
Finally I subscribe on an iOS device and publish from another one but nothing happens.
Be sure to retain the publication and subscription objects. They stop publishing/subscribing when they're deallocated. The usual way is to store them as properties/ivars in one of your classes.
The developer docs are misleading on this point, and I apologize. We'll improve the docs in the next release.
During researching of the PrivateFrameworks that are available at iOS 9 i found interesting library that could give access to the call history of the jailbreak iPhone. The question is how to use this framework?
Brief example of my :
NSBundle *b = [NSBundle bundleWithPath:#"/System/Library/PrivateFrameworks/CallHistory.framework"];
BOOL success = [b load];
if (success) {
Class CallHistoryDBHandle = NSClassFromString(#"CallHistoryDBClientHandle");
SEL theSelector = NSSelectorFromString(#"fetchAllNoLimit");
id si = [CallHistoryDBHandle valueForKey:#"createForClient"];
NSLog(#"-- %#", [si performSelector:theSelector]);
} else {
NSLog(#"NO");
}
This question already has answers here:
Return value for function inside a block
(3 answers)
Closed 8 years ago.
Updated:
I am trying to call a method from a different class and put it in an if statement saying "if the uploadPhoto method is true then display success for testing purposes" here is my updated code:
PhotoScreen *script = [[PhotoScreen alloc] init];
if ([script uploadPhoto])
{
NSLog(#"Sucess!");
}
It isn't giving me the error anymore but when I summit the photo from the uploadPhoto method, it does't log the "Success" And here is my uploadPhoto method:
- (BOOL)uploadPhoto
{
//upload the image and the title to the web service
[[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"upload",#"command",
UIImageJPEGRepresentation(photo.image,70),#"file",
fldTitle.text, #"title",nil]
onCompletion:^(NSDictionary *json)
{
//completion
if (![json objectForKey:#"error"])
{
//success
[[[UIAlertView alloc]initWithTitle:#"Success!"
message:#"Your photo is uploaded"
delegate:nil cancelButtonTitle:#"Yay!"
otherButtonTitles: nil] show];
}
else
{
//error, check for expired session and if so - authorize the user
NSString* errorMsg = [json objectForKey:#"error"];
[UIAlertView error:errorMsg];
if ([#"Authorization required" compare:errorMsg]==NSOrderedSame)
{
[self performSegueWithIdentifier:#"ShowLogin" sender:nil];
}
}
}];
return YES;
}
What am I doing wrong?
You method needs to return a BOOL. In your method you should have the statement return YES; somewhere if the method succeeds and a return NO; if it fails. You can modify your code to the following:
PhotoScreen *script = [[PhotoScreen alloc] init];
if ([script uploadPhoto])
{
NSLog(#"Sucess!");
}
The repetitive method calls were unnecessary along with the comparison.
I didn't have this problem with fb SDK 3.2, but after I upgraded it in SDK 3.5.1 friend inviter has some strange problem, when I select one friend it choose the selected one and the one under it. Also when I am trying to scroll downward it restarts the table and brings me back on the tables top.
Here is my method:
-(IBAction)secondClick:(id)sender
{
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:nil];
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Learn how to make your iOS apps social."
title:#"Test"
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or sending the request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
// Handle the send request callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"request"]) {
// User clicked the Cancel button
NSLog(#"User canceled request.");
} else {
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:#"request"];
NSLog(#"Request ID: %#", requestID);
}
}
}
}];
From what i have come to know is that facebook has fixed this issue and is going to make the fix live soon.
An alternate solution to this is to make your own custom UI.
1. Get Friends List - [self startConnectionWithGraphPath:#"me/friends" parameters:params method:#"GET" completionSelector:#selector(callback)]
Download pictures using url #"https://graph.facebook.com/fbid/picture"
Implement a table view similar to facebook's request ui showing list of friends along with their profile pics.
Use 'to' param to direct the request to the selected user(s). NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: #"286400088", #"to", nil];
This way you won't need to show facebook ui to select friends. Al though the UI will still appear after user selects friends from your custom UI, but that'd be just to tap 'send'.
One way is to use the Facebook friendPicker
https://developers.facebook.com/ios/friendpicker-ui-control/
And then take the facebook id's result of that and put them into the requestdialog just like Nitin said.
I'll post my friendPicker code:
- (IBAction)inviteFriendsClicked:(id)sender {
// Initialize the friend picker
FBFriendPickerViewController *friendPickerController =
[[FBFriendPickerViewController alloc] init];
// Set the friend picker title
friendPickerController.title = #"Välj vänner";
// TODO: Set up the delegate to handle picker callbacks, ex: Done/Cancel button
// Load the friend data
[friendPickerController loadData];
// Show the picker modally
[friendPickerController presentModallyFromViewController:self
animated:YES
handler:
^(FBViewController *sender, BOOL donePressed) {
if(donePressed) {
NSString *userString;
userString = #"";
int *counter = 0;
for (id<FBGraphUser> user in friendPickerController.selection) {
NSLog(user.id);
NSMutableArray *userArray = [[NSMutableArray alloc] init];
[userArray addObject:user.id];
if(counter == 0){
userString = user.id;
}else{
userString = [NSString stringWithFormat:#"%#%#%#", userString, #",", user.id];
}
counter++;
}
if(counter != 0){
[self requestDialog: userString]; // Display the requests dialog and send the id-string with it
}
// NSLog(#"Selected friends: %#", friendPickerController.selection);
}
}];
}
I'm in sandbox mode implementing game center in my application. The problem comes when I log to gameCenter, in some devices works fine in some others I get a GKErrorCanceled without even get the interface shown.
This devices don't have any user logged in gameCenter so it's not related to have a non sandbox account logged. My code is:
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
//First we try the new iOS6 authentification method for gamekit, if it's not implemented we will use the deprecated one
if ([localPlayer respondsToSelector:#selector(setAuthenticateHandler:)]) {
if (localPlayer.isAuthenticated) {
this->setState(connectionLoged);
this->getDelegate().socialConnectionDidSucceedLogin(*this);
return;
}
else if(!localPlayer.isAuthenticated && localPlayer.authenticateHandler){
this->setState(connectionClosed);
this->getDelegate().socialConnectionDidFailToLogin(*this, std::string("The user already resign to login"));
return;
}
else{
localPlayer.authenticateHandler = ^(UIViewController* viewController, NSError* error){
if (localPlayer.isAuthenticated)
{
_name = [localPlayer.displayName UTF8String];
_userId = [localPlayer.playerID UTF8String];
[GKPlayer loadPlayersForIdentifiers:localPlayer.friends withCompletionHandler:^(NSArray *players, NSError *error) {
for (GKPlayer* player in players) {
if ([player isFriend]) {
NSDictionary* dict =
#{#"displayName" : player.displayName,
#"alias" : player.alias,
#"playerID" : player.playerID};
AttrDictionary* playerInfo = [dict hydraAttrDictionary];
SocialFriend* socialfriend = this->getNewFriendInstance(*playerInfo);
this->addFriend(socialfriend);
delete playerInfo;
}
}
this->getDelegate().socialConnectionDidSucceedLogin(*this);
this->setState(connectionLoged);
}];
}
else if(viewController){
UIViewController* rootViewController = (UIViewController*) [UIApplication sharedApplication].keyWindow.rootViewController ;
[rootViewController presentModalViewController:viewController animated:YES];
}
else{
if(error){
this->getDelegate().socialConnectionDidFailToLogin(*this, std::string([error.description UTF8String]));
}
else{
this->getDelegate().socialConnectionDidFailToLogin(*this, std::string("User cancelled login"));
}
}
};
}
}
//deprecated at IOs 6 authentification method
else
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated)
{
_name = [localPlayer.displayName UTF8String];
_userId = [localPlayer.playerID UTF8String];
[GKPlayer loadPlayersForIdentifiers:localPlayer.friends withCompletionHandler:^(NSArray *players, NSError *error) {
for (GKPlayer* player in players) {
if ([player isFriend]) {
NSDictionary* dict =
#{#"displayName" : player.displayName,
#"alias" : player.alias,
#"playerID" : player.playerID};
AttrDictionary* playerInfo = [dict hydraAttrDictionary];
SocialFriend* socialfriend = this->getNewFriendInstance(*playerInfo);
this->addFriend(socialfriend);
delete playerInfo;
}
}
this->getDelegate().socialConnectionDidSucceedLogin(*this);
this->setState(connectionLoged);
}];
}
else{
NSString* errorString = [error localizedDescription];
this->getDelegate().socialConnectionDidFailToLogin(*this, std::string([errorString UTF8String]));
this->setState(connectionClosed);
}
}];
I need the code compatible with iOS 6 and iOS 5 so you will see I have the two implementations. For iOS 6 the completion handler returns with an UIViewController null and the error as I say. I'm afraid that in production it happends the same. In the simulator all works fine.
PS- You will find some c++ code, it's because I implement a c++ wrapper for GameCenter as my game is write in cocos2dx...
When someone cancels out of the interface to sign in to game center, it will give you GKErrorCanceled. The third time in a row that they cancel, it will warn them that it will disable game center.
If they do choose to disable game center, then it won't show the interface anymore, and it will just give you GKErrorCanceled instead.
Once game center has been disabled, the only way to sign in is by going into the actual game center app.
The 3 times in a row could be in any app or any combination of apps that use game center, and game center will be disabled for all apps that use game center. The 3 times in a row restarts every time they sign in to game center.
This is for both sandbox and non-sandbox.
This is for both ios 5 and ios 6.