I'm trying to make GKTurnBasedMatch's sendReminderToParticipants work correctly in conjunction with Localizable.strings so as to implement 'poke' functionality whereby you poke another player to have their turn.
Here is what my Localizable.strings file looks like:
"POKE" = "%# has poked you!";
It's set to UTF-16 encoding as per below:
And here is my function call:
let messageKey = "POKE"
if opponent?.player?.alias != nil
{
match.sendReminderToParticipants([opponent!], localizableMessageKey: messageKey, arguments: [opponent!.player!.alias!]) { (error) in
if error != nil {
NSLog("Problem poking player: \(error!.description)")
}
}
NSLog("You have poked the opponent for match \(match.matchID). resetting poke date")
APPDELEGATE.pokeMgr.update(match.matchID!)
}
Localizable.strings is included in the "Copy Bundle Resources" of my build phases for my build target
I deleted the app from my device and rebuilt it cleanly.
Issue: It doesn't work! The push notification that is received simply is the default one saying "Your Turn". I must have missed something. Can someone please advise if there is something else I need to have done to make this work?
Related
I am trying to create a custom plugin, based on the Riverside OpenEdge plugin and its version of Proparse to create a rule that valids a &IF preprocessor.
This rule needs to verify if the application is using a deprecated value of a &GLOBAL-DEFINE like this:
/* "A" is the deprecated value of "opts" so I want to create a new ISSUE here */
&IF "{&opts}" = "A" &THEN
MESSAGE "DEPRECATED CODE".
&ENDIF
&IF "{&opts}" > "A" &THEN
MESSAGE "OK CODE".
&ENDIF
For this rule I extended I tried to do something like this:
if (unit.getMacroGraph().macroEventList.stream().noneMatch(macro -> macro instanceof NamedMacroRef
&& ((NamedMacroRef) macro).getMacroDef().getName().equalsIgnoreCase("opts"))) {
return;
}
TokenSource stream = unit.lex();
ProToken tok = (ProToken) stream.nextToken();
while (tok.getNodeType() != ABLNodeType.EOF_ANTLR4) {
if (tok.getNodeType() == ABLNodeType.AMPIF) {
// Verify node.
System.out.println(tok);
}
tok = (ProToken) stream.nextToken();
}
But I don't know if its the best way to verify (I did based on the code from other sources) and it's not working because the next node comes as an empty "QSSTRING". I am very new in the Proparse world, any help is appreciated.
First, you have to know that Proparse doesn't give access to every detail of the preprocessor. That said, the method unit.getMacroGraph() will give you access to the visible part of the preprocessor, so that's a good starting point.
If you're looking for usage of given preprocessor variable, you can search for NamedMacroRef instances pointing to the right MacroDef object (with NamedMacroRef#getMacroDef()#getName()), and the right value.
In a old-style for-each loop:
for (MacroRef ref : unit.getMacroSourceArray()) {
if ((ref instanceof NamedMacroRef)) {
if ("opts".equalsIgnoreCase(((NamedMacroRef) ref).getMacroDef().getName())
&& "A".equalsIgnoreCase(((NamedMacroRef) ref).getMacroDef().getValue())) {
System.out.println("OPTS variable usage with value 'A' at file " + ref.getFileIndex() + ":" + ref.getLine());
}
}
}
On this file:
&global-define opts a
&IF "{&opts}" = "A" &THEN
MESSAGE "DEPRECATED CODE".
&ENDIF
&undefine opts
&global-define opts b
&IF "{&opts}" > "A" &THEN
MESSAGE "OK CODE".
&ENDIF
This gives:
OPTS variable usage with value 'A' at file 0:2
So you don't have access to the expression engine, but I think that the current API is enough for what you want to do.
You can then report the issue with SonarQube with OpenEdgeProparseCheck#reportIssue()
I am teaching myself Apple Development with a Swift OS X 10.10 App. I want to pass a file URL to NSXMLParser. That file is large, and on a seperate disk from my app. I create the NSURL, but when I check it with checkPromisedItemIsReachableAndReturnError(), I always get a "No such file or directory error".
It looks like whe I run my app in Xcode, something is prepending the app's development directory into my file path, so "/Volumes/bigdrive/data.xml" becomes "/Users/charlweed/Library/Developer/Xcode/DerivedData/dataskunk-ghkiumvdkopxarhavynetidlqxio/Build/Products/Debug/file:/Volumes/bigdrive/data.xml"
I did not enable Sandbox, or iCloud when I created the project. I thought I might need to use NSURL.startAccessingSecurityScopedResource() anyway, but it always returns true. What am I doing wrong? Here is a test function in Swift,I don't know objective-c, but I expect I can figure out an objective-c answer:
func accessFile() {
/**I belive this URI is correct, becuase everything after the file:// works in the OS X bash*/
let xmlInFilePath = "file:///Volumes/Seagate_1tib/projects/dataskunk/wasteproduct.xml"
if let xmlInFileURL = NSURL.fileURLWithPath(xmlInFilePath)
{
println("Unwrapped \(xmlInFileURL)")
var securityURLBS = xmlInFileURL.startAccessingSecurityScopedResource()
if securityURLBS
{
var xmlFileError: NSError?
if xmlInFileURL.checkPromisedItemIsReachableAndReturnError(&xmlFileError)
{
println("Can access file. huray!")
/** Use the file URL**/
}
else
{
/** This Always happens with a "No such file or directory " :( **/
println("\(xmlFileError)")
}
}
else
{
println("Could not get Security Scoped Resource")
}
xmlInFileURL.stopAccessingSecurityScopedResource()
}
else
{
log(" NSURL.fileURLWithPath() returned nil for \(xmlInFilePath)")
}
}
Here is the dump of the error:
Unwrapped file:/Volumes/Seagate_1tib/projects/dataskunk/apple_rss.xml -- file:///Users/charlweed/Library/Developer/Xcode/DerivedData/Keepass2Keyring-ghkiumvdkopxarhavynetidlqxio/Build/Products/Debug/
Optional(Error Domain=NSCocoaErrorDomain Code=260 "The file “wasteproduct.xml” couldn’t be opened because there is no such file."
UserInfo=0x61000006f9c0 NSURL=file:/Volumes/Seagate_1tib/projects/dataskunk/wasteproduct.xml -- file:///Users/charlweed/Library/Developer/Xcode/DerivedData/Keepass2Keyring-ghkiumvdkopxarhavynetidlqxio/Build/Products/Debug/,
NSFilePath=/Users/charlweed/Library/Developer/Xcode/DerivedData/Keepass2Keyring-ghkiumvdkopxarhavynetidlqxio/Build/Products/Debug/file:/Volumes/Seagate_1tib/projects/dataskunk/wasteproduct.xml,
NSUnderlyingError=0x610000044a10 "The operation couldn’t be completed. No such file or directory"})
The answer is that NSURL.fileURLWithPath() does not take a URL-path as an argument, only a filesystem-path. So "file:///Volumes/disk/file.xml" is wrong, "/Volumes/disk/file.xml" is correct.
The mangling is NSURL prefixing the current directory onto what it thinks is a relative filesystem-path String.
I'm trying to obtain a digital signature for a XML string using a RSA private key using Swift as command-line script (to be called from FileMaker later).
The compiler kept crashing with "segmentation fault 11" and then "Illegal Instruction: 4" and I kept drilling down until I (think) I found the problem, but it's completely beyond me, so please, please help!! ;) :)
As the title says, when I invoke SecTransformExecute on my SecSignTransform, with a binary version of my String as input attribute, I get the following error message:
Error Domain=Internal CSSM error Code=-2147415790 "The operation
couldn’t be completed. (Internal CSSM error error -2147415790 -
Internal error #80010912 at __SignTransform_block_invoke_2
/SourceCache/Security/Security-57031.1.35/Security/libsecurity_transform/lib/SecSignVerifyTransform.c:279)" UserInfo=0x7fc620e23aa0 {NSDescription=Internal error #80010912 at
__SignTransform_block_invoke_2 /SourceCache/Security/Security-57031.1.35/Security/libsecurity_transform/lib/SecSignVerifyTransform.c:279,
Originating Transform=CoreFoundationObject}
Here is the relevant part of my code:
import Foundation
import CoreFoundation
import Security
var signer: SecTransformRef
var signedData, digestData: NSData
var error: Unmanaged<CFErrorRef>?
var status: OSStatus
var key: SecKey
var anyItem: Unmanaged<AnyObject>?
var keySearchDict: [String : AnyObject]
let keyMatch = "[*place search tag here*]" as String
// turns a string into a binary to sign
let str = "Hello World"
let uintData = [UInt8](str.utf8)
let sourceData = CFDataCreate(kCFAllocatorDefault, uintData, countElements(uintData))
// sets up keySearchDict to query Keychain
keySearchDict = [(kSecClass as String): (kSecClassKey as String), (kSecMatchSubjectContains as String): keyMatch, (kSecReturnRef as String): kCFBooleanTrue]
// gets private key using keySearchDict
status = SecItemCopyMatching(keySearchDict, &anyItem)
key = (anyItem!.takeRetainedValue() as SecKey)
if status != 0 { println("status is: \(SecCopyErrorMessageString(status, &error).takeRetainedValue())") }
// creates SecTransform object using key
signer = SecSignTransformCreate(key, &error).takeRetainedValue()
if error == nil { println("signer transform creation error == nil") } else { println(error) }
// signer to get data from sourceData
SecTransformSetAttribute(signer, kSecTransformInputAttributeName, sourceData!, &error)
if error == nil { println("signer attribute setting error == nil") } else { println(error) }
// execute the transform
//signedData = (SecTransformExecute(signer, &error) as NSData)
let anything = SecTransformExecute(signer, &error)
if error == nil { println("signer execute error == nil") } else { println("erro: \(error!.takeRetainedValue())"); println(CFErrorGetCode(error!.takeRetainedValue())) }
println("anything = \(anything)")
//println(signedData)
I'm not very familiar with objc and actually not quite a proper coder, so please forgive my poor coding style ;) Also, sorry if I'm posting too much of it, but I figured better more than less...
Maybe I'm doing something wrong when transforming the String to binary for signing? I tried it both using CFData and NSData (to make this self contained, I'm using "Hello World" as my String, but in my code I actually load a UTF8 encoded XML from a file using NSData(contentsOfFile:) yet both generate the same error...)
Thanks you so much for your help! It's being a great learning experience, but I've been at it for over a week full-time now, so I really can use a break!! ;) :D
I have found a solution. The code no longer crashes, and I connected to the web service successfully after it, and the XMLDSIG signature was accepted by it (see related Question on XMLDSIG if interested in details on canonicalization and xml reference).
The key I was using is not compatible with signing (not sure why or even what the key was, actually...)
I was looking into counter-authenticating with a server using a X509 certificate (for an unrelated part of my solution) when I came across the SecIdentity class, needed to create a SecCredential together with the certificate and authenticate with the server.
I saw Identities embed a private key, and thought if could work for me. And it did!
Here are the changes I made:
Changed the kSecClass to kSecClassIdentity in the search dictionary
Retrieved the SecIdentity using SecItemCopyMatching
After casting it accordingly, used SecIdentityCopyPrivateKey to retrieve the private key into a SecKeyRef
Used this key in SecSignTransform, and voilà!! It worked!
Here is the working code:
// ...
// get the SecIdentity (substitutes KeySearchDict etc)
idSearchDict = [(kSecClass as String): (kSecClassIdentity as String), (kSecMatchSubjectContains as String): keyMatch, (kSecReturnRef as String):
status = SecItemCopyMatching(idSearchDict, &anyItem)
id = (anyItem!.takeRetainedValue() as SecIdentity)
// Retrieve the private key from SecIdentity
var KeyRef: Unmanaged<SecKeyRef>?
SecIdentityCopyPrivateKey(id, &KeyRef)
priKey = (KeyRef!.takeRetainedValue() as SecKey)
// Create SecSign using the private key
signer = SecSignTransformCreate(priKey, &error).takeRetainedValue()
if error != nil { print("signer transform creation error: ") ; println(error) }
/ signer to get data from sourceData
// ...
I'll post another question with the difficulties I'm facing with XMLDSIG, and add it to the comments, in case anyone is interested. I've already solved that too, and the answer is there in case you need it.
Thanks to everyone who tried to help, and hope this saves someone a lot of time and headache in the future!!
PS: loving Swift, otherwise 😉 😃
This is my first time writing in Swift, Cocoa (have experience in Cocoa Touch), and using Authorization, so I honestly have no idea if I am even on the right track. I am trying to make a modification to the hosts file, which requires user authentication, but both the AuthorizationCreate and AuthorizationExecuteWithPrivileges methods are giving errors.
var authorizationRef:AuthorizationRef
var status:OSStatus
status = AuthorizationCreate(nil, environment:kAuthorizationEmptyEnvironment, flags:kAuthorizationFlagDefaults, authorization:&authorizationRef)
let overwrite_hosts = "echo \(hostsContents) > /private/etc/hosts"
let args = [overwrite_hosts.cStringUsingEncoding(NSUTF8StringEncoding)]
status = AuthorizationExecuteWithPrivileges(authorizationRef, pathToTool:"/bin/sh", options:kAuthorizationFlagDefaults, arguments:args, communicationsPipe:nil)
Me calling AuthorizationCreate is throwing "Type '()' does not conform to protocol 'AuthorizationRef'" and my call of AuthorizationExecuteWithPrivileges is throwing "Could not find an overload for '__conversion' that accepts the supplied arguments"
Any ideas? Am I approaching this incorrectly?
Thanks for any help!
I was able to figure out how to do it via AppleScript, but you should be able to do it using the Authorization method I was trying before, therefore leaving this question open. Anybody looking for a quick solution (no error checks implemented) you can use what I wrote below:
func doScriptWithAdmin(inScript:String) -> String{
let script = "do shell script \"\(inScript)\" with administrator privileges"
var appleScript = NSAppleScript(source: script)
var eventResult = appleScript.executeAndReturnError(nil)
if !eventResult {
return "ERROR"
}else{
return eventResult.stringValue
}
}
how do unity check if player manually sign out from the leaderboard in google play service. I am using the GPG plugin for this and my platform is in android
This is a bit dated, but I was just looking into this and thought I'd share what I found.
When you sign out from within the leaderboard (or achievements page), the GPG plugin gives you an error that looks like this:
** [Play Games Plugin DLL] ERROR: Authentication has been lost!
which causes PlayGamesPlatform.Instance.IsAuthenticated () to return false.
One way to find catch this is simply listening to the script that is displaying the message. Their log function is written below. Just look at the msg arg and toggle your variable you are using to keep track of the logged in state.
- GooglePlayGames > OurUtils > Logger.cs
...
public static void e(string msg) {
Debug.LogWarning("*** " + LOG_PREF + " ERROR: " + msg);
if (msg == "Authentication has been lost!") {
// yourScript.isLoggedIn = false;
}
}
...
Alternatively, you could check the value of PlayGamesPlatform.Instance.IsAuthenticated() when the user attempts to access one of the GPG services (leaderboard, achievements, etc). If it is false, the user is not signed in and should be prompted to sign in rather than firing the service.