随着Facebook的新Android SDK 3.0(几天前发布),身份验证过程发生了变化.
那么你如何申请阅读权限,例如"friends_hometown"?
以下代码是我试图这样做的 - 但我很确定这不是你应该这样做的方式:
版本1:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Session.openActiveSession(this, true, new Session.StatusCallback() { // start Facebook login
@Override
public void call(Session session, SessionState state, Exception exception) { // callback for session state changes
if (session.isOpened()) {
List<String> permissions = new ArrayList<String>();
permissions.add("friends_hometown");
session.requestNewReadPermissions(new Session.NewPermissionsRequest(FBImport.this, permissions));
Request.executeGraphPathRequestAsync(session, "me/friends/?access_token="+session.getAccessToken()+"&fields=id,name,hometown", new Request.Callback() {
...
});
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
版本2:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Session currentSession = Session.getActiveSession();
if (currentSession == null || currentSession.getState().isClosed()) { …Run Code Online (Sandbox Code Playgroud) android facebook facebook-authentication facebook-android-sdk
我的应用程序中有多个不同的Activity,在活动之间切换时我不想要任何过渡动画.以下是我如何在活动之间切换:
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
这在我第一次开始新活动时效果很好.没有动画,但是当我回到已经启动的Activity时,似乎忽略了"Intent.FLAG_ACTIVITY_NO_ANIMATION"并且发生了默认动画.
我似乎无法弄清楚为什么会这样.
我正在插入或替换到我的sqlite数据库中的数据有一些意想不到的结果.为了解决这个问题,我试图在下面的代码中从准备好的sqlite3_stmt(语句)中获得完整的打印.
我想做的是这样的事情,但我知道它不起作用:
if (sqlite3_step(statement) == SQLITE_DONE) {
NSLog(@"%@", statement);
Run Code Online (Sandbox Code Playgroud)
反正有没有完成这个?
谢谢!!
sqlite3_stmt *statement;
const char *dbPath = [databasePath UTF8String];
if (true) {
ListingsObject *temp = (ListingsObject *) DatabaseObject;
if (sqlite3_open(dbPath, &conyDB) == SQLITE_OK) {
const char *insertReplaceStmt = "INSERT OR REPLACE INTO listings (id, association_id, name, email, phone, toll_free_phone, fax, website, street, city, state, zipcode, county, bio, featured, hours, lat, lng, updated, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, …Run Code Online (Sandbox Code Playgroud) 我一直在努力优化我的一些代码,并且我得到了一个关于fors的奇怪结论.
在我的测试用例中,我创建了一个主要活动的新项目.该活动初始化一个包含500个对象的List,运行显式GC并启动该线程.该线程循环函数doCalculations.
this.objects是500 MyObject的列表,以前是MyObject,值是int.函数逻辑没有逻辑,它们就是那里的东西.区别在于内在.
功能1
public void doCalculations()
{
for(MyObject o : this.objects)
for(int i=0; i<this.objects.size(); i++)
if(this.objects.get(i) == o)
o.value = this.objects.get(i).value;
}
Run Code Online (Sandbox Code Playgroud)
功能2
public void doCalculations()
{
for(MyObject o : this.objects)
for(MyObject o2 : this.objects)
if(o2 == o)
o.value = o2.value;
}
Run Code Online (Sandbox Code Playgroud)
使用功能2在我的nexus s上每隔~10秒调用一次GC,释放~1.7MB.
功能1 GC永远不会被看到.
这是为什么?
我们的应用程序偶尔会遇到崩溃(通过BugSense发现),因为看起来内存不足或内存损坏情况,所以为了帮助我跟踪它们,我启用了以下功能:
在模拟器中与应用程序进行一些交互(少于30秒)后,将显示以下消息:
GuardMalloc[TrafficDemoEmp-2430]: allocate_pages(): virtual memory exhaused!
GuardMalloc[TrafficDemoEmp-2430]: expandUniquingTable(): VMCopyFailed
GuardMalloc[TrafficDemoEmp-2430]: allocate_pages(): virtual memory exhaused!
GuardMalloc[TrafficDemoEmp-2430]: expandUniquingTable(): VMCopyFailed
Run Code Online (Sandbox Code Playgroud)
禁用Guard Malloc后,该应用程序运行正常,但启用该应用程序时,这些消息会崩溃.当我使用Leaks和Allocations工具进行配置文件时,没有发现泄漏,并且所有内存的实时字节值都在30 MB到80 MB之间(取决于它当时正在做什么).当然,应用程序的内存不是太多.
但是,消息指向我的应用程序使用太多内存,但我不知道是什么导致虚拟内存耗尽.是否有其他工具或调试器设置可供Xcode使用?
谢谢,
大卫
我按照"使用Facebook登录创建一个新的Android项目"部分的步骤访问https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/登录过程很好.因为我想使用本机Android按钮供用户登录,所以我将以下代码移动到原生Android按钮的View.OnClickListener()中稍微修改代码.以下是侦听器中的代码:
Session.openActiveSession(MainActivity.this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session,SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session,new Request.GraphUserCallback() {
// callback after Graph API
// response with user object
@Override
public void onCompleted(GraphUser user,Response response) {
if (user != null) {
Toast.makeText(getApplicationContext(), "Hello " + user.getName() +" "+user.getId()+"!", Toast.LENGTH_LONG).show();
}
}
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
onActivityResult()和AndroidManifest.xml与教程相同
@Override
public void onActivityResult(int requestCode, int resultCode, …Run Code Online (Sandbox Code Playgroud) android facebook facebook-authentication facebook-android-sdk
我试图从带有货币符号的字符串中获取数字(浮点值).
例如.从"¥1,234"到1234从"AU $ 3,456"到3456从"56.78€"到56.78
我尝试了以下代码,但结果是0.
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setLenient:YES];
NSNumber *number = [formatter numberFromString:text];
NSDecimalNumber *money = [NSDecimalNumber decimalNumberWithDecimal:[number decimalValue]];
float fval = [money floatValue];
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我正在尝试向ActiveAdmin路由添加范围,以便我可以在URL中包含"/:brand".因为bg是品牌而不是localhost:3000/admin/dashboard它localhost:3000/bg/admin/dashboard.
我有我的routes.rb设置如下:
Rails.application.routes.draw do
scope '/:brand', brand: /bg|gwt|acf/ do
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
end
end
Run Code Online (Sandbox Code Playgroud)
登录的路线http://localhost:3000/bg/admin/login非常好.但是一旦登录,我就会收到任何ActiveAdmin资源的以下错误.
ActionController::UrlGenerationError (No route matches {:action=>"index", :controller=>"admin/dashboard"} missing required keys: [:brand]):
actionpack (5.0.0.1) lib/action_dispatch/journey/formatter.rb:50:in `generate'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:629:in `generate'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:660:in `generate'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:707:in `url_for'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:236:in `call'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:295:in `block (2 levels) in define_url_helper'
/Users/computer/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-f8926831429f/lib/active_admin/devise.rb:40:in `root_path'
devise (4.2.0) lib/devise/controllers/helpers.rb:178:in `signed_in_root_path'
devise (4.2.0) lib/devise/controllers/helpers.rb:214:in `after_sign_in_path_for'
devise (4.2.0) app/controllers/devise_controller.rb:114:in `require_no_authentication'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:382:in `block in make_lambda' …Run Code Online (Sandbox Code Playgroud) 我有一个很好的任务,就是使用带有Rails的大量SOAP api.SOAP服务有三种不同的绑定; wsHttpBinding,wsHttpBinding与x509,以及自定义绑定.我只能使用wsHttpBinding来击中两个端点,但是第三个端点需要用户名和密码,这与之无关.我因为证书而避免使用x509,并且自定义绑定在SoapUI中运行良好,但是使用Savon我得到以下错误.
由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理带有Action''的消息.这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配.检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无).
我已经使用了Savon生成的确切XML并将其放入SoapUI并且它可以工作.
这是一个具有约束力的问题吗?有没有办法告诉它使用这个自定义绑定?
这是我在App.config中找到的自定义绑定
<bindings>
<customBinding>
<binding name="cust">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
<binding name="cust1">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
<binding name="cust2">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<endpoint address="http://api.xyz.com/stuff.svc/cust"
binding="customBinding" bindingConfiguration="cust" contract="stuff.Xstuff"
name="cust" />
Run Code Online (Sandbox Code Playgroud)
编辑#1
这是我当前的客户端设置,这有助于它.
@client = Savon.client(
wsdl: 'http://api.xyz.com/stuff.svc?wsdl',
wsse_auth: %w'username password',
wsse_timestamp: true,
raise_errors: false,
log: true,
log_level: :debug,
soap_version: 2,
pretty_print_xml: true,
convert_request_keys_to: :none,
use_wsa_headers: true,
headers: {'Content-Type' => 'application/soap+xml; charset=utf-8'}
Run Code Online (Sandbox Code Playgroud)
编辑#2
我发现了这个问题.Savon没有像SoapUI那样在Content-Type中设置动作.感谢@RicardoPontual建议再次尝试比较Savon和SoapUI请求,这让我更仔细地看一下并注意到这个问题.
headers: {'Content-Type' => 'application/soap+xml;charset=UTF-8;action="tempuri.org/stuf??f/set_table_stuff"'}
Run Code Online (Sandbox Code Playgroud) 我试图找出一种方法来解析美元金额中的"$"和",".
例如,假设我有一个5,600美元的字符串.我需要解析它,所以我剩下的只有5600.任何帮助都非常感谢.
谢谢你,凯文
我需要帮助才能在EditText视图中输入一个小数点.一个例子:我不想要123.45.2或被123..452允许.输入一个小数点后,不再允许.
我正在尝试自定义搜索栏.我已经想出如何更改搜索栏中的背景和文本框,但我找不到更改栏中默认图标的方法(放大玻璃图标).
有没有办法做到这一点?
我希望在它上面有一个EventTouchDown时更改UIButton的alpha.我希望有一种方法可以做到类似于下面的代码:
[self.myButton setImage:<#(UIImage *)#> forState:UIControlEventTouchDown];
Run Code Online (Sandbox Code Playgroud)
有没有办法用"setAlpha"做这样的事情?
谢谢!!!