我们的应用有不同的通知,可以打开不同的活动.所以我们创建了URI方案来实现这一点.收到通知并打开正确的活动.我使用以下代码创建用于正确导航的堆栈:
Intent intent = new Intent(Intent.ACTION_DEFAULT, Uri.parse(uri));
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntentWithParentStack(intent);
PendingIntent contentIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager mNotifM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder mBuilder = new Notification.Builder(context);
mNotifM.notify(NotificationId.getID(), mBuilder.setStyle(new Notification.BigTextStyle(mBuilder)
.bigText(bigText)
.setBigContentTitle(title)
.setSummaryText(summaryText))
.setContentTitle(title)
.setSmallIcon(R.drawable.udechile_launcher)
.setContentText(summaryText)
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setTicker(bigText)
.build());
Run Code Online (Sandbox Code Playgroud)
问题是在Android 4.1.1中,重新创建堆栈的代码无法正常工作.我使它工作的唯一方法是在创建intent时引用类而不是uri:
intent = new Intent(context, MatchDetail.class);
Run Code Online (Sandbox Code Playgroud)
这个问题是我必须为每个uri做一个Switch-Case才能为每个类创建意图.这首先打败了URI的目的.此外,如果将来我需要添加一个新的推送目标不只是在AndroidManifest.xml中添加URI我必须在推送通知接收器的开关中添加新的情况.
有人知道如何在Android 4.1.1中使用URI进行此工作吗?
清单摘录:
<activity
android:name=".controller.MatchDetail"
android:label="@string/title_activity_match_detail"
android:parentActivityName=".controller.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".controller.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="scheme" android:host="base" android:path="/name" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud) Swift 1.2/XCode 6.4
我有以下代码:
public protocol MapShape : AnyObject
{
func isEqualTo(other : MapShape) -> Bool
}
Run Code Online (Sandbox Code Playgroud)
还有一个我尝试遵循该协议的通用类
public class MapMulti<T:MapShape>
{
let items : [T]
init(items : [T])
{
self.items = items
}
}
extension MapMulti : Equatable {}
public func ==<T:MapShape>(lhs: MapMulti<T>, rhs: MapMulti<T>) -> Bool
{
return true //simplify code
}
extension MapMulti : MapShape {
public func isEqualTo(other: MapShape) -> Bool {
if (object_getClassName(other) == object_getClassName(self))
{
return self == other as! MapMulti
}
return false …
Run Code Online (Sandbox Code Playgroud) 我有以下结构:
class Entity : Object {
dynamic var Id = 0
dynamic var Title = ""
dynamic var Subtitle = ""
var atttribute : MyProtocol?
Run Code Online (Sandbox Code Playgroud)
}
有没有办法在属性中存储一些东西?今天返回零。如果我添加动态,它会返回错误:
Property cannot be marked dynamic because its type cannot be represented in Objective-C
Run Code Online (Sandbox Code Playgroud)
有没有办法存储符合协议的属性?
我有以下表示点或线的结构:
public struct Point{
let x : Double
let y : Double
init (x : Double, y : Double)
{
self.x = x
self.y = y
}
}
extension Point : Equatable{}
public func ==(lhs: Point, rhs: Point) -> Bool
{
return lhs.x == rhs.x && lhs.y == rhs.y
}
Run Code Online (Sandbox Code Playgroud)
和
public struct Line {
let points : [Point]
init(points : [Point])
{
self.points = points
}
}
extension Line : Equatable {}
public func ==(lhs: Line, rhs: Line) -> …
Run Code Online (Sandbox Code Playgroud) 具备以下条件:
配置文件
{
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"jsx": "react",
"module": "commonjs",
"moduleResolution": "node",
"experimentalDecorators": true,
"declaration": true,
"outDir": "lib",
"lib": ["es2015","dom"]
}
}
Run Code Online (Sandbox Code Playgroud)
注意声明:true
和.tsx文件:
import * as styledComponents from "styled-components";
export const backColor = (props: MyProps) => props.theme.backColor;
export const Title = styledComponents.div`
text-align: center;
background-color:${backColor};
width: 100%;
`;
Run Code Online (Sandbox Code Playgroud)
当我tsc
在终端上运行编译时,我得到:
错误 TS2339:属性 'div' 在类型 'typeof "/root/node_modules/styled-comp...' 上不存在。
更新
两种导入样式组件的方式都会发生错误
import styled from 'styled-components'
import * as styled from 'styled-components'
Run Code Online (Sandbox Code Playgroud)