我使用django-push-notifications在Django
服务器中实现推送通知。
我已经为我的GCM
网络应用实现了AngularJS
,并且在chrome上运行良好。对于野生动物园,我遵循this post来实现APNS
部分,但出现此错误:
"POST /v1/pushPackages/web.com.example HTTP/1.1" 200 5722
{u'logs': [u'downloading push notification package failed']}
这是我的 views.py
@api_view(['POST','GET'])
def getPushPackage(request):
try:
print "Here -- > Hello"
filename = '/pushNotifications/static/pushPackage.zip'
zipfile = open(settings.BASE_DIR+filename, 'rb')
response = HttpResponse(content=zipfile)
response['Content-Type'] = 'application/zip'
response['Content-Disposition'] = 'attachment; filename="%s"' %(settings.BASE_DIR+filename)
print "Here -- > Done"
return response
# return HttpResponse(content=zipfile, content_type='application/force-download')
except Exception as e:
print str(e)
return Response(str(e))
这是我的 urls.py
url(r'^v2/pushPackages/web.com.example', views.getPushPackage),
url(r'^v1/log', views.printPushError),
这是我的控制器
var checkRemotePermission = function (permissionData) {
console.log(permissionData.permission);
if (permissionData.permission === 'default') {
// This is a new web service URL and its validity is unknown.
window.safari.pushNotification.requestPermission(
'https://x.x.x.x:1234', // The web service URL.
'web.com.example',
{}, // Data that you choose to send to your server to help you identify the user.
checkRemotePermission // The callback function.
);
}
else if (permissionData.permission === 'denied') {
console.log("here user denial");
// The user said no.
}
else if (permissionData.permission === 'granted') {
// The web service URL is a valid push provider, and the user said yes.
console.log("here");
console.log(permissionData.deviceToken);
// permissionData.deviceToken is now available to use.
}
};
// functions end
if(browser == "Safari")
{
console.log( "In safari" );
if ('safari' in window && 'pushNotification' in window.safari) {
var permissionData = window.safari.pushNotification.permission('web.com.example');
checkRemotePermission(permissionData);
}
}